here

CS 310, Spring 2015: Programming Assignment
(100 points)
Assigned: March 17, 2015
Due date: March 31, 2015
You will practice the programming for the array data type. Array is quite common in
many real applications. In this specific assignment, we use an “image” or “photo” as the
array data. A nice property of image is that you can view the original data and new data
after your operations, i.e., you can change the array elements (pixel values in an image)
and see the effect directly and intuitively.
Specifically you will do the following:
 Write your code using C/C++, Java, C#, Python, or any others except Matlab.
 You may use either Unix or Windows system, lab computer or your own laptop.
 You are provided with two images of the PGM format. This format is only for
grayscale images, rather than color images. See the following link for details on
PGM image, http://netpbm.sourceforge.net/doc/pgm.html.
 You can use XnView (for Windows) or XV (for Unix) to display images or
transform other image formats into .pgm, such as from .jpg, .gif, etc.
 The original color images are shown at the end of this assignment, while the
grayscale images can be downloaded at the link in the course web site.
 In addition to these two images, you can try more if you like.
 You need to write your code to read the .pgm images. From the header of the
.pgm image, you can read the size (width and height) of an image, and then the
specific pixel value (one byte, from 0 to 255) for each location in an image.
 You also need to draw a rectangle of size 100x100 with the top left corner at (50,
50) location of each image, after you read each image. You can use the bright
pixel value, like 255 for drawing the four sides of the rectangle. Then you save
the new image (with the rectangle) in another .pgm image.
 You need to submit a short report which includes brief descriptions on (1) how to
read an image; (2) how to draw the rectangle; (3) how to save the result as a new
image; (4) the printed images of the original and generated with a rectangle in
each; and (5) how to view the images with XV or other software. You can print
out your code and turn in it with your report together.
 Each image is considered as an array. You may use dynamic array to save the
image data and do operations on it.
 You can work with your teammates for the programming assignment.
 You should not copy other people’s work for your assignment. The TA may pick
up some groups to run their programs for a test or demo later.
1
Scene 1
Scene 2
2