CSC 427: Data Structures and Algorithm Analysis
Fall 2004

HW3: Matrices and Inheritance

For this assignment, you will extend the Pixmap class that was discussed in lectures, in order to allow for more transformations on portable images. Currently, the operations defined for a Pixmap are Read (from a file), Horizontal Reflect (alogn the x-axis), Vertical Reflect (along the y-axis), Invert (negative image), and Write (to a file). The Pixmap class works on images of type PBM, PGM, and PPM by making use of a hierarchy of Pixel classes: MonoPixel, GrayPixel, and ColorPixel. For this assignment, you will need to add new member functions to the Pixmap class, and correspondingly add member functions to all of the classes in the Pixel hierarchy. Note: polymorphism should be preserved by your additions. That is, your new member functions in the Pixelmap class should work no matter which type of image is is being manipulated.

To get started, you will need to download the following files: Pixel.h, Pixel.cpp, Pixmap.h, Pixmap.cpp, Matrix.h and pix.cpp. For testing purposes, you will also want to download an image viewer that can display PBM/PGM/PPM files. A popular free viewer, IrfanView, is available for downloading at The image files reed.pbm, reed.pgm, and reed.ppm are available for your viewing pleasure.

For each of these new operations, modify the Pixmap and Pixel clases appropriately, then add the corresponding menu options to pix.cpp for testing.

doubles the dimensions of the image and expands each pixel accordingly. For example, a 10x20 image would be enlarged to 20x40, and the pixel at (0,0) would be expanded to fill (0,0), (0,1), (1,0), and (1,1).

sharpens the picture by scaling the pixel values to use the largest range possible. If max and min are the maximum and minimum pixel values in the picture, respectively, then each pixel is assigned a new value as follows: newPixelValue = (oldPixelValue - min) * maxPossiblePixelValue / (max - min) Note: any rounding should occur as late as possible.

blurs the picture (and so removes any perturbations) using the median smoothing algorithm. Each pixel should be replaced by the median value stored in that pixel and the eight adjacent pixels.

overlays the picture read from an input stream on top of the current picture. That is, corresponding pixels are added using modulo arithmetic (i.e., adding 1 to the maximum possible pixel size wraps around to 0). In order for an overlay to make sense, the two pictures must be of the same type and size. Otherwise, an error message should be displayed and no changes made to the current image.

splits the image into two files, whose names are specified by the user. The first file should have random values for each pixel, and the second should have pixel values assigned so that the two images, when overlaid, produce the original.

Advice: Attempt this assignment in stages. Implement one member function at a time, add the corresponding menu option to the driver program, and then test that function thoroughly before beginning on the next one. Before testing functions on large pictures, try them out on small, hand-made pictures for which you can accurately predict the desired effect.