CS 140 - Lab 15 Instructions

Objectives

  1. Compare two colors and change a pixel based on their "closeness" to each other. For example, removing red-eye from a photograph.

Method

Part I - Removing Red Eye

  1. Write down the formula for finding the distance between two points in three dimensional space. Call these points (x1,y1,z1) and (x2,y2,z2)
  2. The code below allows a user to pick two colors, which are then assigned to the color objects c1 and c2.
      
       Color c1 = ColorChooser.pickAColor();
       Color c2 = ColorChooser.pickAColor();
      

    In a Lab15 class add the two lines above and then write a Java expression that calculates and then prints the distance between the colors c1 and c2. You'll need to use the Math.sqrt(x) function to compute the square root. Also helpful is the function Math.pow(x,y) which computes x to the y power. For example Math.pow(3,7) computes three to the seventh power. You will also need to include the line import java.awt.Color; at the top.

  3. What two colors have the greatest distance? What is that distance?
  4. Use the red-eye removal method we wrote in class to remove the other red eye on the cat. Show the instructor.

Part II - Turning Blue Skies Gray

  1. Comment out the code from part one. In this part we're going to turn the blue sky in the picture yippee.jpg to gray. Write a Picture method blueToGray to do this. This method should take as parameters the starting and ending coordinates of the region we want to convert (just like the redeye method did). The way this method should work is that when you see a blue pixel use its RGB values to change the pixel gray. You'll need to experiment with what it means to be close to blue.

Extra Credit - Background Subtraction

Write a Picture method that removes the green background on moose.jpg.


© Ed Harcourt