Last spring break, my family went to England. One day, sitting on the London Underground after a long day of sightseeing, I noticed a perfect geeky photographic opportunity: my son, daughter, and wife were sitting across from me, wearing red, green, and blue jackets, respectively. "RGB" popped into my brain, so I snapped a quick picture.
Now, as I brood over the many ways I could ask you to modify existing images, this picture returns to my attention. Could you make the whole image negative, with whites turned to blacks, darks to lights, etc.? Could you make Sam's jacket purple without changing the rest of the picture? If so, what would happen to his eyes or lips? Could you replace his jacket with another image--perhaps the water in the left side of this picture (from San Diego's Seaworld, a few years earlier)?
The answer is surely yes: you could do all those things, and thus, I'm going to ask you to do so.
You can think of a digital image as a long array of pixels, each of which has a red value, a green value, and a blue value between 0 and 255. Suppose, for example, that you have an image that is 200 pixels wide and 100 pixels high. Pixel numbers 0 through 199 pixels in our imaginary array form the top row of the image, pixels 200-399 form the second row, etc.
The class EasyBufferedImage gives you
some tools for manipulating standard image files of type jpg, gif, or png, using an array
like the one described above. To get started using this class, first retrieve copies of
EasyBufferedImage.java
and ImageProcessorTest.java either via these
links or from the /Accounts/courses/cs117/ondich/jackets/
directory.
While you're at it, save copies of the pictures above: jackets.jpg
and water.jpg.
Your mission is to create a class called ImageProcessor
that contains a
EasyBufferedImage
object as a private variable. You
should then write the following methods:
public ImageProcessor( String filename ) throws IOException
public void show( String title )
show( String title )
method on
your private image.public void show( String title )
show( String title, int x, int y )
method on
your private image. The x
and y
allow you to position your
image windows for convenient viewing.public void removeGreenAndBlue()
public void negate()
public void replaceRed( Color replacementColor )
Color
class
has object methods getRed()
, getGreen()
, and
getBlue()
, which you may find useful to pull apart
replacementColor
. You only need to solve the first
subtlety to get full credit for this problem (i.e., a single shade of
purple covering the red jacket is ok), but you get major coolness
bonuses and a sense of accomplishment if you solve the second
issue.public void replaceRed( EasyBufferedImage replacementImage )
Test your program by using
ImageProcessorTest.java
. Comment out the portions of
ImageProcessorTest.java
that refer to methods that you
haven't written yet so that you can test your code as you go.
Note that though I have provided you with two images to use for testing, you
are welcome to use your own images. The only real restriction is that the two images you
use for the replaceRed( EasyBufferedImage replacementImage )
method
need to be the same size. Two images from the same digital camera with the same settings
usually work fine. If not, you can use lots of kinds of software (e.g. the Paint program
that comes standard with Windows) to modify the sizes of existing images.
Good luck, and have fun.