Movies, particularly action movies that use a lot of special effects, often use a technique called "blue screening". In blue screening, the actors in a scene are filmed as they perform in front of a blue screen. Later on, after the scene has been filmed, the special effects people remove the blue from the scene and replace it with the actual scene: a dinosaur, the New York City skyline, outer space, etc.
In this assignment, you will be using the same technique to insert pictures of Dave Musicant and Amy Csizmar Dalal (one of the other Carleton cs profs) into different scenes.
Remember that 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, each of which is an integer 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 in our imaginary array form the top row of the image, pixels 200-399 form the second row, etc.
In order to modify the image, you need to "loop through" all of these pixels, one at a time, and do something to some or all of the pixels. For example, to remove all of the green color value from each pixel, this is the procedure you would use (in English):
for each pixel in the image set the green value of the current pixel's color to 0 done
Create a directory called image1 for this assignment. To facilitate reading in, storing, and manipulating image files in
"standard" formats (like .jpg, .gif, and .png), we will use a class
called EzImage
.
Copy EzImage.java
into your directory from the above link
or from the course directory. The documentation for
EzImage
can be found here.
You'll also need some images to work with. Download background1.jpg, background2.jpg, background3.jpg, dave.jpg, and amy.jpg into the same directory as
EzImage
.
We'll start out with some basic image manipulations first. Your
task is to write a class called PhotoLab
. It should
contain the following methods:
public EzImage onlyRed(EzImage image)
public EzImage negate(EzImage image)
Test your program by running PhotoLabTester.java
on all four of the images.
Now that you've got the hang of manipulating images, let's go back to this idea of blue screening. The pictures named background*.jpg depict some sort of scenery, while the other two (dave.jpg and amy.jpg) are clearly just people standing against a plain background (in this case, a wall instead of a blue screen). We can "combine" these images into a single image by replacing the "wall" pixels in one of the people pictures with pixels from one of the scenery pictures. To do this, we have to figure out which pixels correspond to the wall (and can be changed) and which ones correspond to the person (and should be left alone).
Modify your PhotoLab
class so that it contains the
following additional methods:
public EzImage replaceWall(EzImage image, Color
replacementColor)
Color
class contains the methods getRed()
,
getGreen()
, and getBlue()
, which you may
find useful here.public EzImage replaceWall(EzImage originalImage,
EzImage replacementImage)
Test your program by running PhotoLabTester2.java
. Feel
free to use your own pictures here if you'd like.
Identifying which pixels are in the wall is tricky. Here's what worked for me. Any pixel that satisfied the following counted as part of the wall:
red value >= 100 and green value >= 100 and absolute value of difference between red value and green value < 30 and absolute value of difference between red value and blue value < 30 and absolute value of difference between green value and blue value < 30
(The last three conditions express the idea that the values of each of the colors must be similar, i.e. gray.)
What are some of the problems you encountered while trying to remove the wall pixels and retain the "person" pixels? Could you do better? Answer these questions briefly in a plain text file named README.If you complete the above methods (and other things like style, etc. are correct), you will receive 19 out of 20 points for this assignment. You should feel proud and good about yourself that you have gotten this far, and feel free to stop here! If you want to try to earn the remaining point write one more method:
public EzImage textureWall(EzImage image, Color
replacementColor)
If you look closely at the pictures of Amy and Dave, you'll notice
that the background is not a solid color: it contains some texture.
The textureWall
method is a variation on the first
replaceWall
method that preserves the texture of the
background wall. In other words, calling textureWall
with
a parameter indicating purple would produce a purple brick
wall. Modify PhotoLabTester2.java
as necessary to test
your code.
In your README file, please explain what strategy you used to keep the texture of the wall while replacing it with another color. How well did this strategy work?
Turn in the .java
code for all of the classes you've written or modified for this assignment, along with your README file. If you used any of your own pictures for this assignment, you may want to turn those in too.