SUNY Geneseo Department of Mathematics

Lab 7—Image Processing

Math 230 02
Spring 2015
Prof. Doug Baldwin

Complete by Wednesday, April 15
Grade by Friday, April 17

Purpose

This lesson reinforces your understanding of vectorization and matrices in Matlab, and introduces you to some basic ideas behind digital images and image processing.

Background

This lesson is built around implementing a “green screen” (more technically known as “chroma key”) effect, in which a uniformly colored background in one image is replaced with another image to create a picture showing someone or something in a place they never really were. In the following, I will refer to the image whose background is being replaced as the “subject” image, and the replacement background as the “background” image.

A general introduction to digital images is available at http://cs.geneseo.edu/~baldwin/reference/images.html. Section 13.2 of Attaway’s text describes how to work with some of these ideas in Matlab. We will talk about this material in class on April 8.

This exercise also emphasizes using vectorized computations in place of loops in Matlab. Vectorization is discussed in section 5.4 of Attaway’s text, and will be covered in class on April 6.

You will almost certainly need to do some amount of ancillary image processing outside of Matlab in this lesson. At the very least, you will have to scale your subject and background images to be the same size, and you might find it helpful to have a source of image statistics to gauge the range of colors in your background image. I can do some of this for you, but there are also many free image processing programs that you can download to your own computer. For example, ImageJ, available at http://imagej.nih.gov/ij/, is well respected and very capable.

Activity

Write a Matlab function that takes two images, a subject and a background, and a description of the key color(s) in the subject to replace with background as its parameters. The two image parameters should simply be n-by-m-by-3 arrays. The description of the key color(s) should consist of one or more arrays or other values that specify a range of colors. This function should return a chroma-keyed composite of the subject and background images.

Do not use loops in your compositing function. All the computations you need can and should be vectorized.

Note that this function returns, but does not display, the composite image. The function’s caller can do whatever it likes with that composite—quite likely display it, but maybe do further processing on it, or write it to a file, etc.

Extra Credit

For up to 4 points extra credit, see what other sorts of image processing you can implement as Matlab functions. Vectorize those functions where possible. Examples of things you might consider include…

Many if not all of these will require you to do some reading on your own to understand the problems and get ideas for algorithms for solving them.

Follow-Up

I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring a written solution to the exercise to your meeting, as that will speed the process along.

Sign up for a meeting via Google calendar. If you worked in a group on this exercise, the whole group should schedule a single meeting with me. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.