CS 107: Pictures and Sounds: Programming with Multimedia
Kalamazoo College
Spring 2008
Programming Project 1
Creating 3D Images
This programming project may be done individually or in groups of two.
Keep in mind that you may not work
with the same person on more than two
of the programming projects, excluding the final
project. If you work with a teammate, hand in one
copy of your code with both names on it. It is okay to get help from the
TAs and/or the instructor if you get stuck, but you should try to do it
on your own first.
The objective of this project is to use color manipulations to create
3-dimensional pictures.
3D Effect
Anaglyph images are used to provide a stereoscopic 3D effect, when viewed
with 2 color glasses (each lens a different color). Images are made up of two
color layers, superimposed, but offset with respect to each other to produce
a depth effect. Usually the main subject is in the center, while the foreground
and background are shifted laterally in opposite directions. The picture contains
two differently filtered colored images, one for each eye. When viewed
through
the "color coded" "anaglyph glasses", they reveal an integrated stereoscopic
image. The visual cortex of the brain fuses this into perception of a three
dimensional scene or composition.*
For this assignment, you will combine two images into a single 3-
dimensional image. These images will be viewed using red/blue glasses to
give the 3D effect. With the red/blue
glasses, one eye will only see the red channel, while the other eye will
see the green/blue channel.
The two images will need to be pictures of the same thing taken from a
slightly different viewpoint. The first image will view the object just
to the left of the view of the second image. These two images will then
be combined into a single, new image. At each pixel in this new image,
the amount of red will come from the corresponding pixel in the left eye
image, while the amount of green and blue will come from the
corresponding pixel in the right eye image.
You will need to make sure that the two images have the same width and height
before attempting to create the 3D image.
Examples
The following images were obtained from cameras on the Mars Exploration Rover.
The image on the left represents what the left eye would see; the image on the
right what the right eye would see. The image on the far right is the
3D image.
You will need red/blue glasses to see the last image in 3D.
This next set of images is of a robot on a CS prof's desk, taken on a regular digital camera.
In the first row, the image on the left is the left eye image and the image
on the right is the right eye image. In the second row, the first
image is the
3D image, and the second image is the 3D image obtained by converting the images
to grayscale first. (Some sources have suggested that color
information is lost when converting images to 3D in this manner, so the
images may just as well be converted to black and white, first.)
Again, you will need a pair of red/blue glasses to see the
depth in the last two images.
This final set of pictures was obtained by taking a few pictures of
the quad with a regular digital camera. Again, the left eye image is on the left,
the right eye
image is on the right, and two versions of the 3D image are in the second row.
Part 1: Obtaining Pictures
There are several possibilities for obtaining images to make into 3D images.
In each possibility, there must be an image representing what the left eye would
see, and another representing what the right eye would see. You may need to
experiment with different possibilities to find something you like.
Possible methods for obtaining images include:
- Obtain stereographic images on the web (legally, not violating any copyright
policies). The Mars Exploration Rover website
- Use Google Earth to capture images. Within Google Earth, find a view that
you like (preferably one with 3D buildings), and capture it as an image. Then
move the view just slightly and capture another image. How you change the
view will dictate which is the left eye image and which is the right. (I found
this to be a little tricky.)
- Take pictures yourself. To do this, pick a subject you find interesting.
Inanimate objects with some texture or depth, within 10-15 feet of you, seem
to work best. People don't make great choices in this situation because they
have a tendency to move. Take one photo with your left eye looking through
the view window. Then, without moving your head, slide the camera over just
enough so that you can now take a picture with your right eye looking through
the view window. It is really important to keep the camera level while doing
this. Alternatively, you may try identifying something in your view to line the
camera up with (some cameras have little boxes in the viewing window to
help you with this). Take the picture, and then move the camera over a
little bit (about the distance between your eyes), line up the camera in
the same way, and take another picture. It may take a few attempts to get this right. If you want to try this
and don't have a digital camera, check with one of your instructors.
Part 2: Extracting Red and Green/Blue
In order to create 3D images, we will extract the red from the left
eye picture, and the green and blue from the right eye picture. We will
then create a new image (the 3D image) which takes the red from the left
eye picure, and the green and blue from the right eye picture.
- Write a function that takes two pictures as parameters, one representing
a left eye image, and one representing a right eye image. These pictures must
have the exact same width and height. This function will create a new picture
the same width and height as the originals. The pixels in this new picture
will get their red values from the left eye image, and their blue and green
values from the right eye image. The new picture should be returned at the
end of the function.
- (Optional, but check it out.) If you are working with color photos, you may find that it is easier to see
them in 3D if you first convert them to grayscale. You may copy and use one of your grayscale
functions from Lab 2 to do this.
- Experiment with different images until you find something creatively pleasing. Save your
3D image as a new .png image. You can save it as a .jpg
image, but the compression used with .jpg causes us to lose some color
information related to the 3D perspective.
- Create a web page for this programming project. Be sure to
include a link to it from your course page. Post the original left and right images, and the corresponding 3D image on your web page for this project. (As a reminder, if you haven't been doing so, you should be including text on your web page to describe what it is these images are/what manipulations you have done to them.)
- Be sure you have included appropriate documentation with your
functions. Turn in a hard copy of your function(s), as
well as the URL of your web page.
* Description of anaglyph from Wikipedia: http://en.wikipedia.org/wiki/Anaglyph_image