opening exercise write a method that turns pixels with an
play

Opening Exercise Write a method that turns pixels with an average - PowerPoint PPT Presentation

Opening Exercise Write a method that turns pixels with an average intensity less than 85 to GREEN, pixels with an average intensity less than 170 to RED, and all other pixels to BLUE. What Is Wrong With This Answer? public void exercise01()


  1. Opening Exercise Write a method that turns pixels with an average intensity less than 85 to GREEN, pixels with an average intensity less than 170 to RED, and all other pixels to BLUE.

  2. What Is Wrong With This Answer? public void exercise01() { for ( Pixel p : this.getPixels() ) { double averageIntensity = p.getAverage(); if ( averageIntensity < 85 ) p.setColor( Color.green ); if ( averageIntensity < 170 ) p.setColor( Color.red ); if ( averageIntensity < 256 ) p.setColor( Color.blue ); } }

  3. Guarded Action manipulate a pixel only if it satisfies a particular condition the if statement if ( condition is true ) take the action

  4. Alternative Action Idea manipulate a pixel in one way if it satisfies a particular condition or in another way if it satisfies a particular condition

  5. Alternative Action Implementation the if-else statement if ( condition is true ) take one action else take the other action

  6. Range Selection Using nested if-else statements to find ranges: if ( value is in the first range ) take the first action else if ( value is in the second range ) take the second action ... else take the final action

  7. One Hallmark of Good Design "When making a design choice, always have at least two alternatives. That way, you can at least know that you are not doing the worst possible thing." — paraphrased from Kent Beck

  8. Finding Objects in Images Boundaries appear when neighboring pixels have very different colors. This is the task of edge detection .

  9. An Application of Edge Detection computer vision

  10. Boolean Conditions if ( condition is true ) ... simple boolean expression x < y p.colorDistance(epsilon) conjunction ( and ) x < y && p.colorDistance(epsilon) disjunction ( or ) x < y || p.colorDistance(epsilon)

  11. Homework 2 What are the high-level operations? • insert the image • draw a box (several times) • draw a horizontal line • draw a vertical line Design your solution in this way: • create an empty method for each operation • design, implement, and test each method one at a time

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend