|
Winter Quarter 1998-1999
S-331, 277-7339
PurposeThe 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. OverviewWe 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. AssignmentWeek OneIn the first week you will write a menu driven program with the following options:
Week TwoIn the second week you will add the following menu items:
Implementation DetailsImage file formatAll 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 0would 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 ComputationsThe 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:
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. 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: 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. Week Two ComputationsIn 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:
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. 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. 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. 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 CreditFor extra credit, you may choose to:
Deliverables Timeline
Project ReportYour 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:
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. |