University of Wisconsin Computer Sciences Header Map (repeated with 
textual links if page includes departmental footer) Useful Resources Research at UW-Madison CS Dept UW-Madison CS Undergraduate Program UW-Madison CS Graduate Program UW-Madison CS People Useful Information Current Seminars in the CS Department Search Our Site UW-Madison CS Computer Systems Laboratory UW-Madison Computer Sciences Department Home Page UW-Madison Home Page

Assignment 2: Image Modification

This assignment is intended to introduce you to how to work with pixel data. We will provide you with the source code to a program which can load and save targa images, and you will be expected to write a function which modifies the image in some way.

The TargaImage class has member variables called height, width, and data. The image data, stored in the data member, is an array of unsigned characters, with groups of four characters representing each pixel. Within those four bytes, the first represents the red channel, the second green, the third blue, and the fourth alpha. (The alpha channel contains information about the transparency of a pixel, which is used in compositing. For now, treat it just like you would red, green or blue.) So, to access the blue channel of the 7th pixel, one might write:

#define RED_CHANNEL   0
#define GREEN_CHANNEL 1
#define BLUE_CHANNEL  2
#define ALPHA_CHANNEL 3

int pixelID = 6;
int Bpp = 4;
unsigned char blue_channel = data[pixelID*Bpp + BLUE_CHANNEL]; 
      

Rows of image pixels are stored sequentially in the array, so to access pixels in rows after the first, you must add 4 (bytes per pixel), times the width of a row, times the row number you wish to access. To access the green channel of the 33rd pixel on the 19th image row, one might write:

int rowNumber = 18;
int colNumber = 32;
unsigned char green_channel = data[(rowNumber*width + colNumber)*Bpp + GREEN_CHANNEL];
      

When setting image data bytes, be sure to remember that unsigned characters have a range of 0 to 255.

The TargaImage class also has a method called Modify which you are to implement. It will be called by the GUI when the "Modify Image" button is pressed, and is to make some change to the image of your own design. You might resize (and resample) the image, invert it, add a gradient to the image, rotate it, flip it, or do anything else to it you can imagine (and figure out an algorithm for).

It would be a good idea to read over and understand all the code provided to you in the project. Be sure to take note of how the GUI buttons interact with the rest of the program.

A Visual Studio project and accompanying source code can be found at:

http://www.cs.wisc.edu/~cs559-1/assignments/assignment2/assignment2.zip
Back to CS559 Home Page