Image Processing 2

This assignment is to be done with your partner.

Introduction

Movies, particularly action movies that use a lot of special effects, often use a technique called chroma key. With chroma key, the actors in a scene are filmed as they perform in front of a solid color screen (perhaps green, or blue). Later on, after the scene has been filmed, the special effects people remove that color 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.

Getting Started

Create a directory called image2 for this assignment. To facilitate reading in, storing, and manipulating image files in "standard" formats (like .jpg, .gif, and .png), we will use a module called images.py. Copy images.py into your directory from the above link or from the course website. The documentation for images.py can be found here.

If you're working on your home computer, you'll also need to install the Python Imaging Library (PIL), which images.py uses. Follow these instructions for installing PIL under Windows XP or Mac OS X. We already have PIL installed on the department Macs.

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 images.py, or alternatively use your own image files.

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 solid color 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).

Create a Python module called photolab2.py. It should contain the following functions:

Test your program by an appropriate main() function, which you should also submit as part of your photolab.py. Feel free to use your own pictures 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.

Textures

If you complete the above functions (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 function:

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 function is a variation on the first replaceWallWithColor function that preserves the texture of the background wall. In other words, calling textureWall with a set of colors defining purple would produce a purple brick wall. Modify photolab2.py 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?

What to turn in

Turn in your photolab2.py along with your README file. If you used any of your own pictures for this assignment, you may want to turn those in too.


Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 306 to help out if you need it.