Debrief PA02 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Debrief PA02

Description:

You MUST follow directions. Follow my names EXACTLY. Provide the expected ... it wasn't clear in my directions, if I give you a start ... Get the distance ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 15
Provided by: BenSc
Category:
Tags: debrief | directions | get | pa02

less

Transcript and Presenter's Notes

Title: Debrief PA02


1
Session 15
  • Debrief PA02
  • More work with Conditionals

2
General Things
  • Start Early
  • Ask Questions!! (Harald has hours on Wed)
  • You MUST follow directions
  • Follow my names EXACTLY
  • Provide the expected parameters EXACTLY
  • Pay attention to return types (if not listed,
    there probably isnt one)
  • Do NOT show/repaint in your methods unless
    instructed to do so
  • These were to work on ANY image

3
Task 1
  • Many of you dont have BOTH methods required.
  • Those who do often didnt name correctly
  • You were told this was a looping lab
  • Watch that your borders actually MEET (some of
    you wrote code that didnt produce a complete
    rectangle)

4
Task 2
  • Takes an image
  • Returns a NEW image exactly the correct size
    (dont use the blank canvas)

5
Task 3
  • Takes an image parameter
  • Returns a new image exactly the correct size
  • While it wasnt clear in my directions, if I give
    you a start X of 100 and a finishX of 200 the
    width of this should be 101 (ditto the height)

6
How would a computer see
One way computers see is to attempt to
determine the boundaries between items in an
image.
7
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

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

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

11
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

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

13
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?

14
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