Finishing up enlarging pictures - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Finishing up enlarging pictures

Description:

Red Eye Algorithm. Use the explorer to find the RGB values of the 'red' eyes ... If we still have time... What would we do to take a picture to true Black and White? ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 14
Provided by: BenSc
Category:

less

Transcript and Presenter's Notes

Title: Finishing up enlarging pictures


1
Session 14
  • Finishing up enlarging pictures
  • Removing Red-Eye

2
Review Scaling Up
0
1
2
  • Copy each pixel in the source multiple times to
    the target
  • Source (0,0) Target (0,0)
  • Source (0,0) Target(1,0)
  • Source (1,0) Target(2,0)
  • Source (1,0) Target(3,0)
  • Source (2,0) Target(4,0)
  • Source (2,0) Target(5,0)
  • Source (0,0) Target(0,1)
  • Source (0,0) Target(1,1)

0
1
0
1
2
3
4
5
0
1
2
3
3
Another way to Scale Up
0
1
2
  • Copy each pixel in the source only once.

0
1
2
0
1
3
4
0
1
2
4
Another way to Scale Up
0
1
2
  • Copy each pixel in the source only once.
  • For the remaining empty pixels, insert the
    average of the two neighbor pixels.

0
1
2
0
1
3
4
0
1
2
5
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

6
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!

7
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
8
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)

9
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)

10
Oops, MOSTLY got rid of the red eye but also
11
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

12
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)

13
If we still have time
  • What would we do to take a picture to true Black
    and White??
Write a Comment
User Comments (0)
About PowerShow.com