Red Eye - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Red Eye

Description:

Red Eye Algorithm. Use the explorer to find the RGB values of the 'red' eyes ... And turns all pixels white where the absolute value of the difference between ... – PowerPoint PPT presentation

Number of Views:121
Avg rating:3.0/5.0
Slides: 19
Provided by: BenSc
Category:
Tags: eye | red | whiteeye

less

Transcript and Presenter's Notes

Title: Red Eye


1
Session 15
  • Red Eye
  • (working with conditionals)

2
Remove Red Eye
  • Red eye is when the flash from the camera is
    reflected from the subjects eyes
  • We want to change the red color in the eyes to
    another color

3
Red Eye Algorithm
  • Use the explorer to find the RGB values of the
    red eyes
  • For every pixel in the Picture find the distance
    between the current color and our definition of
    red
  • And change the color of the current pixel only if
    the current color is within some distance to the
    desired color
  • Wait, we need to know TWO new things in order to
    do this!

4
New thing 1 Conditional Execution
  • Sometimes we want a statement or block of
    statements executed only if some expression is
    true
  • We can use the if statement in Python
  • if (colorDistance lt value)
  • Statement 1
  • Statement 2, etc
  • next statement

false
if (expression)
true
Statement or block
statement
5
New thing 2 Color Distance
  • The distance between two points is computed as
  • Square root of (( x1 x2)2 (y1 y2)2)
  • The distance between two colors can be computed
  • Square root of ((red1 red2)2 (green1-green2)2
    (blue1 blue2)2)
  • There is a method in the Pixel class to do this
  • dist distance(color1,color2)

6
removeRedEye() method
  • def removeRedEye(picture)
  • redEye makeColor(155,25,35)
  • for pix in getPixels(picture)
  • if (distance(redEye,getColor(pix)) lt 50)
  • setColor(pix,black)

7
Oops, MOSTLY got rid of the red eye but also
8
Detailed Red Eye Algorithm
  • Loop over a subset of the pixels
  • Requires we give it starting and ending points
    for both x and y
  • This allows us to leave the shirt alone while
    also using a wider distance for redEye

9
Remove Red Eye Method
  • def specificRemoveRedEye(pic,startX,startY,endX,en
    dY)
  • redEye makeColor(155,25,35)
  • for x in range(startX,endX1)
  • for y in range(startY,endY1)
  • pixel getPixel(pict,x,y)
  • if (distance(redEye,getColor(pixel)) lt
    75)
  • setColor(pixel,black)

10
How would a computer see
One way computers see is to attempt to
determine the boundaries between items in an
image.
11
Edge Detection
  • Loop through all the pixels in the picture
  • Calculate the average color for the current pixel
    and the pixel at the same x but y1.
  • Get the distance between the two averages
  • If the distance is greater than some value turn
    the current pixel black
  • Otherwise turn the current pixel white

12
Conditionals
  • What is different about the conditional statement
    in this problem versus the conditional statement
    in the removeRedEye() problem?
  • This has two situations

13
Use if and else for two possibilities
  • Sometimes you want to do one thing if the
    expression is true
  • and a different thing if it is false

false
if (expression)
else
true
Statement or block
Statement or block
statement
14
Edge Detection Algorithm
  • To find areas of high contrast
  • Try to loop from row 1 to row height
  • Loop from x 1 to x width 1
  • Get the pixel at the x and y (top pixel)
  • Get the pixel at the x and (y 1) bottom pixel
  • Get the average of the top pixel color values
  • Get the average of the bottom pixel color values
  • If the absolute value of the difference between
    the averages is over a passed limit
  • Turn the pixel black
  • Otherwise turn the pixel white

15
Edge Detection Exercise
  • Write a method edgeDetection that takes an input
    limit
  • And turns all pixels black where the absolute
    value of the difference between that pixel and
    the below pixel is greater than the passed limit
  • And turns all pixels white where the absolute
    value of the difference between that pixel and
    the below pixel is less than or equal the passed
    limit
  • Pixel has a getAverage() method that returns the
    average of the three colors at the pixel

16
Edge detection (an alternative to Program 40)
  • def topDownEdge(source,limit)
  • for y in range(1,getHeight(source))
  • for x in range(1,getWidth(source)1)
  • top getPixel(source,x,y)
  • bottom getPixel(source,x,y1)
  • if (distance(getColor(top),getColor(bottom
    )) lt limit)
  • setColor(top,white)
  • else
  • setColor(top,black)

17
What about the other way?
  • Create another method for simple edge detection
  • This time compare the current pixel with the one
    to the right (x1)
  • How do you need to change the nested loop?
  • Do you get a different result?

18
Comparing left/right instead of up/down
  • def leftRightEdge(source,limit)
  • for x in range(1,getWidth(source))
  • for y in range(1,getHeight(source)1)
  • left getPixel(source,x,y)
  • right getPixel(source,x1,y)
  • if (distance(getColor(left),getColor(right
    )) lt limit)
  • setColor(left,white)
  • else
  • setColor(left,black)
Write a Comment
User Comments (0)
About PowerShow.com