CSE1020 Lab 06

Part 1: Removing Red-Eye from a Picture

Pictures

Warning: this question uses a package that is installed in the Prism labs; it won't run on your home computer (unless you know how to use a jar file (which is located here)).

A color digital picture (such as a JPEG or PNG file) is a regular grid of pixels (picture elements) having a color defined as a triplet of integer numbers (r, g, b) corresponding to the amount of red, green, and blue.

The number of rows of pixels in the picture is given by the height of the picture and the number of columns of pixels is given by the width of the picture.

princeton.introcs.Picture is a class that lets you manipulate individual pixels of an image. You can find its API here.

 

Red-Eye

The red-eye effect in photography is a common phenomenon of red pupils in color photographs that typically occurs when using a flash. The red color is caused by the light of the flash reflecting off the interior surface of the eye, which has a rich blood supply.

Source: http://en.wikipedia.org/wiki/File:BoldRedEye.JPG

 

Removing Red-Eye

A simple algorithm for removing red-eye from a picture is the following:

for each column i in the picture
   for each row j in the picture
      r = the amount of red   in pixel (i, j)
      g = the amount of green in pixel (i, j)
      b = the amount of blue  in pixel (i, j)
      if r > (g + b)
         replace the pixel color with the color (0, g, b)
      end if
   end for
end for
 

Removing Red-Eye

Cut-and-paste the following (incomplete) program into your editor. The program will run if you compile it, and it will show the original red-eye image.

Modify the program so that it implements the red-eye removal algorithm shown in the section above.

import princeton.introcs.Picture;
import java.awt.Color;

public class RedEye
{
   public static void main(String[] args)
   {
      final String FILE = "/cse/dept/www/course_archive/2011-12/F/" +
                          "1020/labs/06/redeye.jpg";
      Picture pic = new Picture(FILE);
      
      // your code goes here


      // next line should be the last line of your program
      pic.show();
   }
}
 

You should be able to reproduce the following image:

 

Submit

Submit your program using the command:

submit 1020 L06 RedEye.java

And then continue to Part 2.