[MSOE Homepage]

Dr. Taylor's MSOE Homepage

Courses

Unix is a Four
Letter Word

Photo Album

Personal Homepage

CS-182 Main page

Example submission with figures (text)

Example submission with figures (pdf)

CS-182 -- Final Project - Image Processing

Winter Quarter 1998-1999



Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor

S-331, 277-7339
t a y l o r@m s o e.e d u (remove spaces)
www.msoe.edu/~taylor/

Purpose

The purpose of this project is to provide the student with an opportunity to implement the solution to a "real-world" problem. The project is designed to make use of many of the concepts discussed throughout the quarter.

Overview

We don't have to look very far to find digital images. Digital images can be found on the internet. Digital cameras produce digital images. Many film developers, in addition to the standard film development process, offer to scan the film and provide digital images on disk or via email.

Frequently digital images seem to suffer from low quality. In this project, you will write a program to enhance the quality of digital images. In addition, you will write a function that will identify the objects in an image by detecting edges in the image.

Assignment

Week One

In the first week you will write a menu driven program with the following options:

  • Load image.
  • Compute negative of image.
  • Gamma correct image.
  • Save image.

Week Two

In the second week you will add the following menu items:

  • Blur image.
  • Sharpen image.
  • Find edges in image.

Implementation Details

Image file format

All of the images used in this project are stored in the portable graymap (PGM) format. This format was chosen mainly for its simplicity however, it is a fairly common image format on Unix systems. IrfanView (freeware for non-commercial use) and Lview (shareware, $30) are image viewers for MS Windows systems that will display images in the PGM format. Torres has a program called XV which will display PGM images as well.

A digital image consists of a number of dots of light. Each dot is called a pixel. A pixel of a grayscale image consists of one number which indicates the lightness (or intensity) of the image at that location. A pixel of a color image consists of three numbers (each indicates the intensity of red, green, or blue present in the image at that location).

An image file looks like:

P2
# eyes.pgm
480 227
255
227 227 227 227 227 227 228 228 228 227 227
227 227 227 227 225 225 225 227 227 227 225
226 226 226 226 226 226 226 226 226 226 226
...

The first line (P2) indicates that the image format (grayscale stored as ASCII values). Any line that begins with a # is a comment and should be ignored when reading the image. The third line contains two numbers which indicate the width (480) and height (227) of the image. The fourth line contains a number one less than the total number of gray levels (255 indicates that there are 256 gray levels ranging from 0 to 255). The remaining lines are the actual gray levels for each pixel. The pixels are ordered from the upper-left corner of the to the lower-right corner. For example, the following file:

P2
# example.pgm
3 3
255
17 255 0 32 65 128 128 98 0
would appear as:
 17  255    0
 32   65  128
128   98    0

The first item in your menu should ask the user for a file name and read the image into a vector of vectors. Note: You will want to convert the integer values to doubles so that the computations performed on the images do not suffer from extreme round-off errors. The last item in your menu should ask the user to enter a file name and then save the image to the file in PGM format. Note: You must convert your double numbers back to ints in the range from 0 to 255. (The simplest way to ensure that the numbers remain between 0 and 255 is to set all negative numbers equal to zero and all numbers greater than 255 equal to 255.)

Week One Computations

The photographic process typically involves a camera imaging a scene through its lens onto film. The film is processed to produce a negative. The negative is then used to make a print. It is possible to use a digital scanner to digitize a printed photograph. However, some degradation occurs when the negative is used to make a print. It is possible to avoid this degradation by scanning the negative instead of the print. The result of the scanning is a digitized negative that ranges in pixel values from 0 to 255 (for grayscale images). The image must be processed to look like a "positive" instead of a negative. This processing must take dark pixels and make them light and take light pixels and make them dark. The table below shows the pattern for the processing:

Negative

Positive

0

255

20

235

103

152

250

5

When the second option in your menu is selected, your program should process the image loaded in memory (You should first check to make sure an image has been loaded.) to convert it from a negative to a positive. Below is a negative image that you should use to demonstrate your program. Press shift and click on the image to download the image in PGM file format.

[Negative image]

Another common image processing task has to do with displaying images on different monitors. Photographs produced by digital cameras or scanned from print or negative usually have a process known as gamma correction applied to them. The reason this needs to be done is that the brightness of computer monitors does not increase at a constant rate as the gray level value is increased. Gamma correction involves raising the gray level values to a power gamma (graylevelgamma) before displaying the image.

When the third option in your menu is selected, your program should gamma correct the image loaded in memory. (You should first check to make sure an image has been loaded.) Typical gamma values for monitors range from 1.6 to 2.2, but you should allow the user to specify the gamma value. Your program should then perform the following calculation on each pixel, p, in the image:

p = 255 * (p/255)(1/gamma)

Below (on the left) is an image that has not been gamma corrected. You should use it to demonstrate your program. (After gamma correction, it should look like the image on the right.) Press shift and click on the left image to download the image in PGM file format.

[Uncorrected image] [Corrected image]

Week Two Computations

In week one you created a function for converting scanned negative images into "positive" images and another function to gamma correct the image so that it would display properly on a computer monitor. Both functions produced an output image based on an input image. In these functions, the value of an individual pixel in the output image depended only on the value of the same pixel in the input image.

All three menu items for week two of the project use a powerful image processing technique called digital filtering. Like week one, you will produce an output image that depends upon the input image; however, unlike week one, the value of an individual pixel in the output image will now depend on the value of the same pixel in the input image and its eight closest neighbors.

The calculation for a given pixel is described by a 3x3 matrix that describes how much weight should be given to the pixel in the original image and its eight nearest neighbors. The matrix for the "Blur image" computation looks like:

1/16  1/8  1/16
1/8   1/4  1/8
1/16  1/8  1/16

The matrix indicates that the value of the new pixel should be the sum of:

  • 1/4 * (original pixel value)
  • 1/8 * (sum of the original values of the four horizontal and vertical neighbors)
  • 1/16 * (sum of the original values of the four diagonal neighbors)

Here is a very simple example input image and the corresponding output:

Input                   Output
0  0  0  0  0  0     ?   ?     ?     ?     ?   ?
0  0  0  0  0  0     ?  1/16  3/16  4/16  4/16 ?
0  0  1  1  1  1     ?  3/16  9/16 12/16 12/16 ?
0  0  1  1  1  1     ?  4/16 12/16 16/16 16/16 ?
0  0  1  1  1  1     ?   ?     ?     ?     ?   ?

Note that the upper-left corner pixel in the original image does not have any neighboring pixels above it or to the left of it. Therefore, it is not possible to use our equation to determine the value for the output pixel at that location. At least one neighboring pixel is missing for all of the pixels along the edge of the image. Therefore, we have labeled them with question marks in the output image. One common method for getting around this problem is just to copy the pixel values from the original image to the output image for any pixels that do not have all of their neighbors. Doing so would cause the above output image to now be:

Output
0   0     0     0     0   0
0  1/16  3/16  4/16  4/16 0
0  3/16  9/16 12/16 12/16 1
0  4/16 12/16 16/16 16/16 1
0   0     1     1     1   1

When the "Blur image" option in your menu is selected, your program should process the image loaded in memory (You should first check to make sure an image has been loaded.) by "filtering" the image with the matrix given above. Press shift and click on the image to download a test image in PGM file format.

[Noisy image]

When the "Sharpen image" option in your menu is selected, your program should process the image loaded in memory (You should first check to make sure an image has been loaded.) by "filtering" the image with the following matrix:

-1/9  -1/9  -1/9
-1/9  17/9  -1/9
-1/9  -1/9  -1/9

Press shift and click on the image to download a test image in PGM file format.

[Blurry image]

When the "Find edges in image" option in your menu is selected, your program should process the image loaded in memory (You should first check to make sure an image has been loaded.) by "filtering" the image with the following matrix:

-1/9  -1/9  -1/9
-1/9   8/9  -1/9
-1/9  -1/9  -1/9

Press shift and click on the image to download a test image in PGM file format.

[Gloves image]

Programming consideration: It is always good in program design to consider potential modifications that may be required a some later date. Be sure to keep this in mind when designing your program.

Extra Credit

For extra credit, you may choose to:

  • Support color images as well as grayscale images. Two color images (wildcat.ppm and penguins.ppm) are provide in portable pixmap (PPM) format.
  • Add an additional menu option that will allow the user to pick the values for the digital filter matrix. Experiment with different values and report your observations.
  • Add an additional menu option that will "median filter" the input image. Instead of computing a weighted sum of the pixel and its neighbors, the median filter assigns the median (middle) value of the input pixel and its eight neighbors to the output pixel. What affect does this processing have on an image?

Deliverables Timeline

  • (50 points) At the beginning of Week 9 Lab, you should be prepared to demonstrate your program with the following menu options fully functional:
    • Load image.
    • Compute negative of image.
    • Gamma correct image.
    • Save image.
    Note: No report due.
  • (50 points) At the beginning of Week 10 Lab, you should be prepared to demonstrate your program with the following menu options fully functional:
    • Load image.
    • Compute negative of image.
    • Gamma correct image.
    • Blur image.
    • Sharpen image.
    • Find edges in image.
    • Save image.
    Note: No report due.
  • (200 points) Friday, February 19, 5:00pm Final report due (see below for details).
  • No points will be awarded for anything submitted or demonstrated after the final exam.

Project Report

Your report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report. Your report should include:

  • Purpose
  • Problem Statement
  • Procedure (include reasons for your design decisions, etc.)
  • Documented source code
  • Discussion... Here are some questions to ask yourself when writing your discussion section:
    • Did the functions I wrote work the first time? If not, what did I have to fix?
    • What did I find most interesting about this project?
    • What would happen if I selected the "Compute negative of an image option" on a "positive" image?
    • Was I surprised by any of the program results?
    • What would happen if I tried combining more than one computation before saving and viewing the output image?
    • If I selected "blur image" and then "sharpen" image, would I get my original image back? Why or why not?
    • Could I use some of the other computations to make the "Find edges in image" option to produce more useful results on the test image?
    • Did I ever need to check to see if the image values went outside of the 0 to 255 range, or was my instructor just giving me extra work to do?
  • Conclusions (what you learned, suggestions of how the project could have been better, things you would have done differently, etc.)
  • Example output images (clearly label (by filename) and attach these images separately to your email submission)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.


This page was created by Dr. Christopher C. Taylor, copyright 1999.