CS21 Spring 2004 Homework 8:
Greyscale Image Manipulation Project

Due Sunday, March 20, before 11:30pm

For this assignment, you may work with a partner (and we recommend that you do).

Because this is a larger assignment than usual, this will count as two homework assignments.


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 the constant (WHITE -1) here

	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 hw08 subdirectory:
	% cd ~/cs21/hw08
	% cp ~newhall/public/cs21/hw08/* .
	% ls
	Makefile  README  imageproc.c  libcs21graphics.a  pic.tif  tiff.h display.tcl
Start by reading through the README file for an explaination of how to compile and run the imageproc program.

There is one image file, pic.tif, for you to use, and another, quad.tif, that is useful in testing the quad-split feature. In addition, there are other pictures that you can use in ~newhall/public/cs21/hw08_figs/. Just copy over the ones you want into your working directory:

	% cp ~newhall/public/cs21/hw08_figs/filename.tif .
The starting point code includes a library, libcs21graphics.a, of routines to view covert to/from a tiff image file from/to a 2 dimensional array of pixel values. You do not have to add code to call these functions, as this is already done for your in the imageproc.c file.

The starting point code also uses a Makefile for compiling the program. To build the imageproc executable file, just type 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
15. Quad Split the image 

Extra Credit Special Effects               # feel free to add more of these
----------------------------               # but leave QUIT as the last 
16.                                        # menu option if you do add more 
17. 
18. 
19. 

20. Quit

Your choice: 

Requirements

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

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.

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 Required Features and Some Extra Credit Ideas.

(Grace Hopper image from www.arlingtoncemetery.net)

Original Image (and option 13): Blur:
Flip Horizontally: Scroll Horizontally by -200 pixels:
Flip Vertically: Scroll Vertically 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):
Quad Split Image:
(using the input file pic.tif)
Quad Split Image:
(using the input file quad.tif)
   
EXTRA CREDIT IDEAS: EXTRA CREDIT IDEAS:
8 squares puzzle (extra credit)
(randomly reassigns 9 squares to 8 slots):
A Tiling Effect (extra credit):
EdgeDetect (extra credit): Histogram of pixel values (extra credit):
Corner Split Image (extra credit): Rotate by an arbitrary number of degrees:
this would read in a degree amount entered
by the user (any real value, positive,
negative, or zero) and rotate the image
around the center by that many degrees.

the resulting image can be drawn inside
a circle since corners will not necessarily
fit inside the resulting 480x480 image