Assignment 0

Topic: 
Reading and Writing Images


Jo Chaahe Ho Jaaye, ...

Images ...  please download this image in the following formats, and open them in a text editor. Yes, a text editor, to see what's inside. The first few lines should be (humanly/humanely) readable, and isntructive. The PNM suite of format is quite convenient to use - PGM (greyscale)and PPM (colour). The first line gives the code (P?), the second is a comment line, the third gives the image size (width and height), and the fourth is a scaling factor (usually kept 255, people generally do not mess around with this parameter - `Never trouble Trouble, until Trouble troubles you')
Raw PGM
ASCII PGM
Raw PPM
ASCII PPM
Forget what Francis Bacon said ... images too, are to be tasted, chewed and digested. This assignment will entail writing functions (in C/C++/Java) to read in image data, possibly perform some function on it (such as getting a negative of the original image), and writing out an image.
Cool, isn't it? After all, Thanda matlab ...
Statutory `Warning':  This assignment will not be evaluated - and contains no marks (`Contains no fruit juice or pulp. Contains added flavour.' Not recommended for people below 4 years of academic age.)
 

A Note on Using Colour and Greyscale Images:

There exist numerous colour models. Please feel free to use any one which gives the intensity (they greyscale component). The following is the YUV-RGB model.

Y = 0.299R + 0.587G + 0.114B
U = -0.147R - 0.289G + 0.436B = 0.492(B - Y)
V = 0.615R - 0.515G - 0.100B = 0.877(R - Y)

R = Y + 1.140V
G = Y - 0.395U - 0.581V
B = Y + 2.032U

For RGB values in the range [0,255], Y (the intensity component - the greyscale component) has a range [0,255], U has a range [-112,112] and V has a range [-157,157].
Please ensure that your components after the conversion either way, do not go beyond the above limits! From an implementation point of view, please note that you can use the data type unsigned char for R, G, B and Y; char for U, and int for V.
(Those who have done a course in Graphics would readily point out the approximation here: the above formulae are for R', G' and B': the Gamma-corrected versions of R, G and B, and not the original values.)

Some sample code to read in and write out images:

 The files are test.c and image.h The latter is #include'd in the first one, so you can have the following compilation command (in Unix) to get an executable file named test:
gcc -o test test.c -lm
Click on the links below to download the two files:
test.c
image.h
If you are quite particular about doing things precisely, you can also use the following command:
gcc -g -Wall -o test test.c -lm
What does this do? -g puts in useful debugging information into the executable file test, -Wall issues all possible warnings (useful in trying to set right an errant program!), and -lm links the Unix math library - this is quite useful for common image processing programs.

Sumantra Dutta Roy  Department of Electrical Engineering, IIT Bombay, Powai,
Mumbai - 400 076, INDIA. sumantra@ee.iitb.ac.in