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:

  1. nearest neighbour
  2. bilinear
  3. 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:
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.
interpolate -m bl -s 4 HEADSQ.5.pgm HEADSQ.5.1024.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:

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.