Final Project

CS1440 - Due December 4, 2000


Write a C++ code that allows users to obtain some information on an input image or to manipulate that image. 


Before you can write your code, you need to have some background information on how an image is made. 


An image is made up of blocks called pixels.  Usually, when we refer to an image as an n by m (nxm) image,  we mean that there are n rows and m columns in that image.  Thus, n pixels in each column and m pixels on each row.  That makes n*m pixels all together. 


In a grayscale (black & white) image every pixel has a value between 0 to 255.  The black color is represented with value of 0 and the white color with 255.  Mix colors (gray) are made as we go from 0 to 255, and pure gray is 127 (50% black and 50% white).  Following is an example of a 4x4 image (4 pixels on each column and 4 on each row). 



















The colors in this 4x4 image shown above are:



















To generate this image simply create a file (using Pico, called img1.ppm) and type the following:




4  4


0  255  0  255

255  127  255  0

0  255  160  255

255  86  255  0


Once you save the file then you can view it using an imaging software. In the Xlab you can use the xv software to load your image . To run xv at the prompt type xv.    Since this image is very small, you may enlarge the view size to see the details.


Let’s go back to the project again. 

I will provide you an 8x8 image, for you to test your code. This file is called img.ppm. You need to write the following functions to generate the requested outputs.


Revert :  This function will take the image and revert its pixels.  By revert we mean to convert black to white and white to black.  Here is the equation to revert:   x = |255 -x|.  For instance if a pixel on the original image has the value of 255 after we revert it, it will become 0, a pixel with pixel value of 80 will be converted to 255 – 80 = 175. The reverted image will be written into the new file, img_revert.ppm.  Please note that the first four lines of the img.ppm will be written on the reverted image without any change.


Avrg_column:  This function will take the average of each column and will write the result into the OutData file in the following format:


Avg Col (1) :  ???

Avg Col (2) :  ???




Avrg_row:  This function will take the average of each row and will write the result into the OutData file as:


Avg Row (1) :  ???

Avg Row (2) :  ???


Mean:  This function will compute the average pixel value for the input image. 


STD: This function computes the standard deviation for the input image and will write the result into OutData file.  You can use the following equation to compute the STD. 




In this equation X is the pixel value, N is the number of pixels (nxm), and i is the index used to represent each pixel.

Distribution: This function will compute the following 6 values :

            Average + STD                        Average – STD

            Average + 2STD                      Average – 2STD

            Average + 3STD                      Average – 3STD


This function will write the result into the output file, OutData, in the above format.


In addition to the above functions, you need to include the following functions:


Description: This function tells the user that your program computes the revert of the input image, the average of each column, the average of each row, the average of the image itself, and that it computes the Standard Deviation. 


Read_files: This function will ask users to enter three file names and return the array of strings corresponding to these three files to the main program.  Here is the three files:

1) img.ppm                   2) img_revert.ppm                    3) OutData


The first file is an input file and the last two are output files.

Test_files: This function will test to make sure that the above files are valid and will return the streams corresponding to those files to the main function.


To receive full credit for this project, you need to prepare a report that includes the drawing of your algorithm, the description of each function, and your complete code. Your code must be prepared based on the standard we have (heading, indentations, and comments,..). You also need to include a copy of the input file and the two output files that you have created.


Submit your code electronically:   ~rt/bin/submit1440_???  Finalprj  project.C.