(24) - ICSI201 CHANGE YOUR CLICKER FREQUENCY Set your...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ICSI201 CHANGE YOUR CLICKER FREQUENCY Set your clicker to frequency A B See the back of your clicker for instructions Do NOT turn your clicker off during class!! Your votes will not register, if you forget to set your frequency RESET your clicker to frequency AB CSI 201 Introduction to Computer Science [email protected] http://bls.its.albany.edu LI 95j Lecture 24 Administrivia Administrivia Program Programming Assignment Four is available from the class web page. It is due Monday, November 3rd before midnight. RESET CLICKERS TO FREQUENCY A B In a simple nested FOR loop, how many times would an instruction inside the inner loop execute? for (int x = 0; x < m; x++) { for (int y = 0; y < n; y++) { System.out.println("Q"); } } Assume: 0 < m <= n A. B. C. D. E. Once m times n times (m + n) times (m * n) times RESET CLICKERS TO FREQUENCY A B In a simple nested FOR loop, how many times would an instruction inside the inner loop execute? for (int x = 0; x < m; x++) { for (int y = 0; y < n; y++) { System.out.println("Q"); } } Assume: 0 < m <= n A. B. C. D. A. Once m times n times (m + n) times (m * n) times RESET CLICKERS TO FREQUENCY A B Today's Content... Conditionals Conditionals This material corresponds to chapter six in the text. Remove Red Eye Red eye is when the flash from the camera is reflected from the subject's eyes We want to change the red color in the eyes to another color But not change the red of her dress RESET CLICKERS TO FREQUENCY A B Detailed Red Eye Algorithm Pass the x and y of the starting location, and the x and y value of the end location. Using a nested loop, loop through x and y: Get the pixel at this x and y Get the distance between the pixel color and red If the distance is less than some value (167) then change the color to some passed new color. RESET CLICKERS TO FREQUENCY A B Conditional Execution Sometimes we want a statement executed only if some expression is true We can use the "if" statement in Java if (colorDistance < value) { } //next statement false if (expression) true Statement or block // Statement or block to execute statement RESET CLICKERS TO FREQUENCY A B Copy & Paste into Interactions Pane int x = 2; if (x > 1) { System.out.println("x is > 1"); } System.out.println("x is x = 0; " + x); if (x > 1) { System.out.println("x is > 1"); } System.out.println("x is RESET CLICKERS TO FREQUENCY A B " + x); Distance in 2-Space The distance between two points in a 2dimensional space (2-space) is computed as Thank you, Pythagoras!! c2 = a2 + b2 So, c = c2 RESET CLICKERS TO FREQUENCY A B (x1,y1) c a b (x2,y2) Distance in 3-Space We can extend the notion of distance between 2 points in 2-space to 3-space If the 3 dimensions are x, y, z, then RESET CLICKERS TO FREQUENCY A B Distance in RGB-Space (a particular 3-space) RGB-Space *IS* a 3-space Just think of the 3 dimensions as red, green, blue RESET CLICKERS TO FREQUENCY A B Color Distance The distance between two colors can be computed as There is a method in the Pixel class to do this double dist = pixelObj.colorDistance(color1); Blue Green Red RESET CLICKERS TO FREQUENCY A B Remove Red Eye Method public void removeRedEye(int startX, int startY, int endX, int endY, Color newColor) { Pixel pixelObj = null; // loop through the pixels in the rectangle defined by the // startX, startY, and endX and endY for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { // get the current pixel pixelObj = getPixel(x,y); // if the color is near red then change it if (pixelObj.colorDistance(Color.red) < 167) { pixelObj.setColor(newColor); } // if } // for y } // for x } // method note that the "import java.awt.*;" statement at the top of Picture.java gives us access to java.awt.Color without having to type java.awt... RESET CLICKERS TO FREQUENCY A B Testing removeRedEye String filename = FileChooser.getMediaPath("jenny-red.jpg"); Picture p = new Picture(filename); p.explore(); Color colorObj = new Color(150,150,200); p.removeRedEye(123,96,135,107,colorObj); p.explore(); RESET CLICKERS TO FREQUENCY A B Edge Detection Find the areas of high contrast Turn pixels is this area black Turn all other pixels white In this case, "high contrast" means that two adjacent pixels' average colors (r+g+b)/3 are "very" different RESET CLICKERS TO FREQUENCY A B Edge Detection "very different" means that the absolute value of the difference between their averages is very large double topAverage = pixObj1.getAverage(); double bottomAverage = pixObj2.getAverage(); double contrast = Math.abs(topAverage bottomAverage); RESET CLICKERS TO FREQUENCY A B Edge Detection Algorithm To find areas of high contrast Try to loop from row = 0 to row = height 1 Loop from x = 0 to x = width 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 greater than a threshold value Turn the pixel black Otherwise turn the pixel white RESET CLICKERS TO FREQUENCY A B 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 int x = 200; if (x < 128) { System.out.println("<128"); } else { // so must be >= System.out.println(">=128"); } RESET CLICKERS TO FREQUENCY A B false if (expression) else true Statement or block Statement or block statement Edge Detection Exercise Write a method edgeDetection that takes an int parameter as input: threshold And turns all pixels black where the absolute value of the difference between that pixel and the pixel below is greater than threshold And turns all pixels white where the absolute value of the difference between that pixel and the below pixel is less than or equal to threshold RESET CLICKERS TO FREQUENCY A B Testing Edge Detection String filename = FileChooser.pickAFile(); Picture p = new Picture(filename); p.explore(); p.edgeDetection(10); p.explore(); RESET CLICKERS TO FREQUENCY A B ...
View Full Document

This note was uploaded on 01/17/2009 for the course CSI 201 taught by Professor Doanne during the Fall '08 term at SUNY Albany.

Ask a homework question - tutors are online