Playing with photographs

In this lab exercise, you will use the EzImage class to manipulate some photographs. There are tasks and questions in the text below, and you should do them and answer them to your satisfaction. But you only need to hand in what is described in the "What to hand in" section.

Color

As you have seen before, colors on computers are constructed out of three components: red, green, and blue. "24-bit color" refers to a color system that assigns an 8-bit integer to each of these components, allowing you to construct colors out of red, green, and blue integers ranging from 0 to 255. For example, a particularly strident color purple can be obtained using (R,G,B) = (255,0,255), while a calmer purple comes from (150,20,150).

Some questions about color:

A red moose

Here is a color picture of a moose: .

The program consisting of the classes PhotoLab.java and EzImage.java displays the moose photograph in a small window, and then displays the same photograph with all the green and blue removed in a separate window. Your first job is to make this happen. To do so, make a directory to work in. Then right-click on the PhotoLab.java link and select "Save Link As..." or whatever similar option the browser offers you, and save the file in your working directory. Do the same with EzImage.java and the moose (just right-click on the moose picture above). Then compile the Java files and run "java PhotoLab".

Once you have the program running, read the code in PhotoLab.java. (Though you might find EzImage.java interesting, it's a tougher and much longer bunch of code, and you can use it without understanding all of its internal workings.) To make sense of the EzImage methods, take a look at the EzImage documentation.

To make sense of EzImage, you need to understand the three-dimensional array used by the setPixels and getPixels3D methods. It's pretty straight-forward. This quantity, for example:

moosePixels[0][100][EzImage.redIndex]

represents the red component of the 101st pixel from the left in the top (0th) row of pixels of the photograph. That's row number, column number, and color index constant in the three pairs of brackets. If you let the row number get too big (greater than or equal to moosePicture.getHeight(), to be specific), you'll get an ArrayIndexOutOfBoundsException, and similarly with the column number.

Try this: make the moose green instead of red.

What to hand in

Modify the main method in PhotoLab.java to do print out four separate windows:

Hand in your code via HSP by 11:59PM Monday, November 7. Only one member of a partnership needs to hand the code in, but make sure both of your names are in the comment at the top of the code.

Have fun!