CSc 3610 Programming Assignment #4

Work on this with your assigned partner. Take turns programming and error catching. Turn in one copy, with both names on it.

The first thing in your program should be documentation, just like with homework 1.


  1. Practice pair programming.
  2. Practice designing a program.
  3. Practice implementing a program design in MATLAB.
  4. To get familiar with matrices.
  5. To get familiar with image processing.

Image processing applications are often encountered with bio-informatics. MATLAB works well with images, and provides functions to read, show, and write them. Essentially, you can think of an image as a matrix. We will use grayscale images, meaning that each "color" value is really just a number between 0 and 255, indicating gray level. Black is 0, and white is 255. This way, an image is nothing more than a 2-D matrix of unit8 values.

MATLAB works with images, with commands like imread, imwrite, imshow, and image. Other commands that you may need for this assignment include figure, plot, text, xlabel, and title. Investigate these commands, and find out how you can use them to solve the problem below. Remember that you can access part of an array (or matrix) by giving a range of values. For example, a = b(654:1654, 45:67); will copy the elements in all rows of b between 654 and 1654, and columns 45 and 67, and assign them to a.

Your program should first read in an image file. You can use your own image (such as a picture of you and your partner), or you can use "dog256x256.gif" on qubit. The image data is actually a matrix, grayscale values (0 to 255) for each pixel (picture element) of the image. Then your program should show the image.

Next, your program should use the ginput command to specify a point. Print out what pixels these correspond to, display on the image "point 1 selected", then repeat the process. This way, the user will select 2 corners of the image.

Once the user has selected the points, your program should get the subimage specified by these points, open a new figure, and display the reversed-image of the subimage. That is, all grayscale values should be changed to the opposite shade. White should be turned to black, and vice-versa. For example, a dark gray such as value 5 should appear as a bright white value of 250. A value of, say, 246 would appear as 9.

Your solution must include a function that returns the subimage, given the image, starting row and starting column, and ending row and column. It should check to make sure the values are legitimate, i.e. that the points are on the image.

Your program must be able to work with any image supported by MATLAB. (You do not have to specify the image format.)

Design your program by specifying its behavior, identifying the variables and operations it needs to solve the problem, and then organizing the variables and operations into an algorithm. Then code your design in MATLAB using stepwise translation. Finally, test your program thoroughly.

Note: Be aware of the datatypes that you use. You may have to convert from one to another. For example, a = 11:19 creates a list of double values. Converting it to 8-bit unsigned integer can be done with: b = uint8(a)

E-mail your MATLAB source code to the TA (the TA's e-mail address is : ). Do not e-mail the design, do not e-mail the script/output. Do not CC the instructor in your e-mail. Your e-mail should clearly state who you are, that you are in this class, and what you are e-mailing. Make sure to CC yourself on the e-mail, and bring a printout of the e-mail with you to class (see item 4 below). This e-mail does not need to show the text of the attachment, but it should indicate that there is a(n) attachment(s) and what its name(s) is(are).

Turn In Electronic copies of your files to the TA.

Turn In Hard copies of:
  1. your design (behavior, variables, operations, algorithm)
  2. your source code
  3. a copy of your e-mail to the TA
The printouts of the above must be handed in during class. To be considered "on-time", you must turn in all of the above on-time. Make sure that your printouts use a monospaced font.

Due date: November 7, 2006