Greyscale Image Manipulation Project


For this assignment you and your partner will implement a program that manipulates tiff image files. A tiff image is stored as a 2 dimensional array of pixel values (values between 0 and 255). The dimensions of the array are specified by the constants ROWS and COLS. The color white is represented by the value 255, the color black by 0, and grey values are in between.

The image array is stored as an unsigned char array because only a single byte worth of space is necessary for representing all values between 0 and 255. However, in your code you should think of the array as storing int values between 0 and 255, and write code that manipulates these int values (don't assign an image array bucket a char constant like 'a'). For example, to set a pixel to the second most white value I'd do:

	image[i][j] = 255-1;    // I would really use a constant here (WHITE -1)

	image[i][j] = 'q';	// don't do this even though it is legal C 

I will provide you with a base C program which will read in, write out, and display a 480x480 greyscale TIFF image.

In addition, the starting point code includes a function that prints out the initial menu of options, and the prototypes and partial implementations of all the functions you need to write (you may add additional functions).

Use the function comments as guides on how to implement a feature.

This program requires that you write a large number of functions. However, after you figure out the first couple, they should get a lot easier. I suggest that you start with feature 1 (make negative), and that you implement and test incrementally (i.e. first implement and test feature 1 before starting on feature 2, and so on).

Starting Point Code

To get started you will need to first copy over my starting point code into your hw6 subdirectory:
	% cd ~/cs1/hw6
	% cp ~instructor/public/cs1/hw6/* .
	% ls
	Makefile  README  imageproc.c  libcs1graphics.a  pic.tif  tiff.h
There is one image file, pic.tif, for you to use. In addition, the pictures of you I took in class on Tuesday and a few extra pictures are in my ~instructor/public/cs1/hw6figs/ subdirectory. You can copy any of these over into your working directory:
	% cp ~instructor/public/cs1/hw6figs/me.tif .
This starting point code using a makefile for compiling the program. The README file contains information on how to compile this code using make:
	% make		# compiles imageproc executable file
For more information about using and writing makefiles see: Makefile basics

To run the program:

% ./imageproc
Enter the name of a 480x480 greyscale TIFF image: pic.tif

What do you want to do to your image?
1. Make a negative
2. Flip it vertically
3. Flip it horizontally
4. Switch the top left and bottom right corners
5. Darken
6. Lighten
7. Polarize
8. Scroll the image vertically
9. Scroll the image horizontally
10. Zoom in
11. Blur the image
12. Rotate 90 degrees
13. Revert to the original
14. Sort Rows

Extra Credit Special Effects
----------------------------
15. 
16. 
17. 
18. 
19. 

20. Quit

Your choice: 

Requirements

Each time you enter a choice, the chosen effect should be cumulative. For example, if I choose Lighten 4 times in a row, the image should become more and more light. Option 13 allows a user to revert to the original image. Use the function comments as a guide in how to implement an effect (some examples are shown below too). For some effects, you may need to make a temporary local copy of the image so that you don't lose initial pixel values that your effect is changing.

The initial menu will present you with options for 14 manipulations. You must implement all of options 1-14, and option 20. Figures showing some of the options are shown below.

Extra Credit

For extra credit you can add additional options. More difficult options will be worth more extra credit points. Some suggests are adding edge detection, tiling and splitting effects, the 8 puzzle effect, a histogram of pixel values (you need to handle the case when for a particular pixel value, there are more than 480 instances of it), arbitrary rotate (this one is hard). Some example extra credit features are shown below. However, feel free to come up with your own effects. Here is a link with some information about image processing that may give you some ideas to try out.

Creating Your Own TIF image files

You can modify any image file that you have or that you download off the web for use with this assignment. You can create a 480x480 greyscale tif image file from another image file using the xv program. First open an image file that you have in any format (gif, jpeg, xwd, etc.) of any size:
% xv newpic.gif
Clicking the right mouse button in the window will bring up a menu window. From here you can crop the image and resize the image to exactly 480x480 pixels by selecting the ImageSize->Set Size menu options. Once it is the correct dimension, save it as a greyscale tif file by selecting Save and choosing TIF for Format and GreyScale for Colors.

Examples of options

(Grace Hopper image from www.arlingtoncemetery.net)

Original Image (and option 13) Blur
Flip Horizontally Scroll Horizontally by 200 pixels
Zoom (zoom center selected) Switch top left and bottom right corners
Polarize Negative
Rotate 90 Degrees Sort Each Row (use Bubble Sort)
8 squares puzzle (extra credit)
(randomly reassigns 9 squares to 8 slots)
Venetian blinds? (extra credit)
EdgeDetect (extra credit) Histogram of pixel values (extra credit)
Right Split Image (extra credit) Corner Split Image (extra credit)
A Tiling Effect