Image Interpolation
In Labsheet 1 you built a program that could take raw CT images and
create a PGM image. Now that you are familiar with this image
format we can begin to apply some of the interpolation techniques
described in the lectures.
Two sample PGM images, HEADSQ.1.pgm
and HEADSQ.2.pgm,
provided in the /cslinux/marking/CITS4241/FullHead/8bits-pgm
directory can be used as test data for your program. Each
of these PGM images is of size 256 x 256, with the intensity
value of each pixel (being an unsigned char) in the range [0,255].
Your task in this Labsheet is to write a program that takes a PGM
image
and resizes it as defined by the user. The interpolation methods
that the user can select are:
- nearest neighbour
- bilinear
- bicubic convolution (for those
who wish)
For instance, suppose that your program is named interpolate
and is written in C. Then the following sample
commands should be supported:
- To enlarge the size of the image HEADSQ.1.pgm (by a factor of 2)
to 512 x 512 using
the nearest neighbour interpolation method and save the output image to
HEADSQ.1.512.pgm:
interpolate -s
2 -m nn HEADSQ.1.pgm HEADSQ.1.512.pgm
where the argument immediately after the '-m' flag denotes the user
specified interpolation method; the argument immediately after the
'-s' flag denotes the resize
factor; the input and output image file names must be given last.
- To enlarge the size of the image HEADSQ.5.pgm by a
factor of 4 using bilinear interpolation and save the output image to HEADSQ.5.1024.pgm:
interpolate -m
bl -s 4 HEADSQ.5.pgm
HEADSQ.5.1024.pgm
- To enlarge the size of the image HEADSQ.6.pgm by a factor of 2
using
bicubic interpolation and save the output image to newHEADSQ.pgm:
interpolate
-m bc -s 2 HEADSQ.6.pgm newHEADSQ.pgm
In the above examples, the argument '
nn' denotes that the nearest
neighbour interpolation method is selected; the argument '
bl' denotes bilinear
interpolation; the argument '
bc'
denotes bicubic interpolation. You may choose other argument
names for these 3 interpolation methods in your program.
Note that the '
-m' and '
-s' flags
can appear in any order.
Further hints:
To help you get started, two .C files are provided:
interpolate.c
and
PGMio.c
Details about these files are given below:
- interpolate.c
- this is an incomplete (i.e. it does not call any interpolation
method) C source file that has the main function. You should be
able to compile and run it. It is your task to write functions
that implement the
above interpolation methods and then call these functions appropriately in interpolate.c.
- PGMio.c
- this C source file contains functions for reading/writing PGM files
from/to disk.
Details about how to compile and run the
interpolate program
can be found in the comments given in the C source files.
Two sample input PGM files,
HEADSQ.1.pgm
and
HEADSQ.2.pgm,
can be found in the /cslinux/examples/CITS4241/
directory. Several sample output PGM files can also be found in
the same directory and the description on how these output PGM files
were generated can be found in the README file
there. Use xv
to visualise and compare the differences between the output PGM images
produced by the nearest neighbour and bilinear interpolation methods.