CS 117 Assignment: Blue screening

There are two assignments here (parts 1 & 2): both are pair programming assignments.

Introduction

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 giant spider, the New York City Skyline, Jar-Jar Binks, etc.

In this assignment, you will be using the same technique to insert pictures of Dave Musicant and Amy Csizmar Dalal, the two CS117 professors this term, into different scenes.

Before you proceed further, there are some things that you should know about images and how they are typically stored. 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

Getting started

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 from the course directory into your 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, amy.jpg, and dave.jpg into the same directory as EzImage.

Part 1: Applying basic filters to an image

We'll start out with some basic image manipulations first. Your task is to write a class called PhotoLab. It should contain two EzImage private instance variables: one to store the original image, and one to store the most recent manipulated image. It should also contain the following methods:

Test your program by running PhotoLabTester.java on all four of the images.

Part 2 (most of it): Blue screening

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 (amy.jpg and dave.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:

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? Can you have done any better? Answer these questions briefly in a plain text file named README.

Part 2 (the rest of it): Textures

If you complete the above methods (and other things like style, etc. are correct), you will receive 18 out of 20 points for assignment B. 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 2 points, write two more methods (explanation below):

  • public void textureWall(Color replacementColor)
  • public void textureWall(EzImage replacementImage)

    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 two textureWall methods are variations on the replaceWall methods so that preserve the texture of the background wall. In other words, calling textureWall with a parameter indicating purple would produce a purple brick wall. Likewise, calling textureWall with a background image of Europe would provide a "bricked" image. Modify PhotoLabTester2.java as neessary 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 or image. How well did this strategy work?

    What to turn in

    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.

    This assignment may take you a while, so start early, ask questions, and have fun with it!


    Written by Dave Musicant, Jeff Ondich, and Amy Csizmar Dalal.