CS 397

Assignment 1: Blue Screening

Due 18 September 2007

Overview

The purpose of this assignment is to give you some familiarity with manipulating images. You will read, write, and manipulate images of yourself in front of a blue screen. How you manipulate the images is up to you. It may also be your first introduction to programming in C using the Unix command line.

Setup

I would recommend working on the macs in Mudd 416, for now, although I may be able to convince ITS to put the necessary stuff on the computers in the Olin lab. Mudd 415 will also eventually be available. What you need is a C/C++ compiler, some kind of editor, and some kind of image viewer that will either let you view PPM images or convert them to something else. If you are setting up your own system, Imagemagick and xv are two very useful tools.

Log into one of the macs as labuser. Start X-windows, which will bring up a terminal window in which you can type commands. The most important commands are:

You can use BBEdit to edit C files, or emacs or vim/vi, whatever your preference. BBEdit gives you a GUI and lots of help, so it's good for starting out. It was also designed for programming, so it has a number of useful features.

Before you start writing code, please take a look at the coding style guide.

In one of the X-terminals, you need to make a working directory somewhere. Keep things organized, so you may want to make a "Classes" directory at the top-level, then a cs397-vision directory, and then a directory with your username below that.

Wherever you will be working, make a vision working directory. It will behoove you to plan ahead when organizing your directory structure. There will be numerous programming assignments for this course, and you will be reusing much of your code from assignment to assignment. A suggested directory layout--created automatically by the code archive below--is as follows.

              vision
                 |
       ---------------------
       |      |    |   |    |
      bin include lib src images
                   |   |
                  obj obj

In the first lab we'll go over how to write a makefile that works with this directory structure. You can also take a look at the makefile tutorial.

To read/write TIFF or PPM images, download the following code archive: iolib.tgz. To unpack the code, use the following command in an X-window terminal:

tar xvfz iolib.tgz

Note that the mac may automatically unzip the file, creating a file called iolib.tar. In that case, drop the z from the tar command.

The archive will create a set of working directories and put some basic code into the lib and src subdirectories. This code will allow you to easily read and write 24-bit color TIFF files and 24-bit color ppm files. The files tiffmain.c and ppmmain.c is the src directory are examples of how to use the routines to read, manipulate, and write a TIFF or PPM image, respectively.

To make the programs, go into the lib directory and type make -f makefile.lib (or rename makefile.lib to makefile and just type make).

Note, if the tiff library is not installed on your machine, compiling the library will cause some errors. You can still use the PPM functions, you just need to tell make to not try compiling the tiff functions. Open up the makefile and find the line that starts with _COMMON. Put a # symbol after ppmIO.o to comment out the rest of the line. Then the library ought to compile properly.

Once the library is compiled, go into the src directory and type make. The executable(s) should end up in the bin directory. You can run the program using the X-terminal window.

ppmmain someinputfile.ppm someoutputfile.ppm

Make sure you know how to use xv, or some other general image viewing tool for unix. Gimp or photoshop are also nice tools, but they are like using a bulldozer when all you really need is a shovel. To start xv with an image (e.g. foo.tif), type xv foo.tif on the command line in X. Alternatively, you can just type xv and then use the Load button to select an image to load. (Hint, to get a load button, click on the startup image with the right mouse button.)

In xv, you can view the actual pixel values by clicking on the middle mouse button and moving the cursor around the image. On the macs there is also the DigitalColor Meter in the Applications:Utilities directory. It lets you access the pixel color of any pixel on the screen.

Procedure

  1. Get a picture of yourself taken in front of the blue screen. Your pictures will end up here.
  2. Write a program to read in the images and modify a small block of the image from (0, 0) to (20, 20). Write out the result.
  3. Write a program to change the blue background into something else. Start by just turning it a constant color. Then explore inserting another picture into the image.
  4. Insert multiple, possibly rotated, flipped, or scaled versions of yourself into a single image. This will involve some simple math and proper interpolation, which we'll go over in the lab and in class.

Extensions

Writeup

Follow the writeup instructions to create a web page for your assignment. Send the instructor an email with the code in a zip or tar file along with instructions on how to compile and run it as well as a pointer to the URL for the writeup.