Assignment (1) Ė Data Structures

Due: Friday Jan 21, 2005



All CS3460 students should have a directory 3460 under their home directory by default.If you donít have one, create a directory 3460 (no cs in front).Change to that directory and create a directory assgn1 there.Type pwd to make sure you are in that directory before you start working on your program.I will copy the files from that directory to grade, so it is very important that you complete your work in that directory.Date and time stamp must reflect the due date and time.I will not grade any program that has a date after the due date/time.


Background Information

Before you can write your program, you need to have some background information on how a digital image is made.  A digital image is made up of squares (blocks) called pixels. Usually, when we refer to an image as an n-by-m (n*m) array, we mean that there are n rows each with m columns of pixels in that image. Thus, n pixels in each column and m pixels on each row make n*m pixels all together on the image.  In a grayscale image, every pixel has a value between 0 to 255. The black color is represented with a pixel value of 0 and a white color with a pixel value of 255.  Selecting values in the range 0 to 255 makes different shades of gray. A pure gray is 127 (50% black and 50% white).  Following is an example of a 4x4 image (4 rows with 4 pixels on each row).  Please note that all pixels are square.

††††††††††† ††††††††††† Image†† ††††††††††††††††††††††† ††††††††††† Corresponding pixel values††††††





































The pixel values on this 4x4 image are shown on the right-hand-side.

To generate this image simply create a file called img1.pgm and type the following 8 lines in it:
# This a sample 4x4 image
4  4
255  0  255
255  127  255  0
255  160  255
255  86  255  0

In this image, the first 4 lines define the format and parameters of the image, in brief:
P2  // Is the standard gray image PGM format
# This a sample 4x4 image  // any comments
4  4  // number of rows and columns
255  // maximum gray level observed

Once you saved the file then you can view it using an imaging software, such as xv on cs or Paint Shop Pro, or Adobe Photo Shop on PCs.  Note that since this image is very small, you may enlarge the view (zoom in) to see the details.  You can also use the imaging software to convert images that are in other formats to pgm format.††


Program Description

You will write a program that reads a pgm image and will first find its median.Median is the number that appears in the middle of a sorted set.For example in the following set A = {1, 3, 5, 6, 7}, 5 is the median.If there were even number of values, then the median is the average of the two numbers in the middle.For example for B = {2 4 4 6 7 8 8 9},the median is 6.5.Your program, then will set all the values below the median to 0 and keep those values equal/above the median unchanged.For example if B was representing the image data, after you find the median, the new B would look like this:B = {0 0 0 0 7 8 8 9}.



Your program should contain your name and brief description of its functionality. It should contain sufficient documentation where needed.See the main Assignment Page for the department's Programming Style Guidelines for more details.


This program should contain (at least):

        An image class to keep the image parameters as stated above

        MUST use a pointer as a member of the image class to store the image data

        A function that reads the input image file

        A function that writes the output image back to a file

        A function that finds the median

        A function that sorts the image data.


I let you decide about other functions you may wish to include.I also let you decide about the choice of sort algorithm and function.


You will use multiple files (at least 3) to assemble your program.I let you decide how to break the program down to multiple parts.You will copy an image file from my public directory to test your program.Of course you have to test it first with the 4x4 image that I have given at the beginning of this assignment.


cp~rt/public/Mr3/eb01.pgm.†† (donít miss the . at the end)


The image you will copy from my directory is a 256-by-256 image.After you process the image as explained above, you should get another image of the same size.Note that the output image from your program should have the same exact parameters (top 4 lines) as the input image. You will store the resulting image as neweb01.pgm in your assgn1 directory.


Submission and Deadline

All parts of the program is due on Friday Jan 21 by 5:00 pm.I will copy all programs and the output image from:YourHomeDirectory/3460/assgn1


Make sure to keep all your files there.Since I will copy the files from that directory by 5:00 pm. Files with date/time after 5:00 on January 21 will not be graded.