Barb Ericson Georgia Institute of Technology August 2005

Slides:



Advertisements
Similar presentations
Conditionals-part31 Conditionals – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Advertisements

ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
03-ConditionalsInPictures Barb Ericson Georgia Institute of Technology Feb 2010 Working with ranges in pictures.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Georgia Institute of Technology Declaring Variables – Mod 4 Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Conditionals-Mod8-part41 Conditionals – part 4 Replace background Barb Ericson Georgia Institute of Technology May 2007.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
CSC1401 Using Decisions in Java - 1. Recall from Alice We only wanted to shoot a lightning bolt at a philosopher So, we used the If statement.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Conditionals – part 2 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Conditionals-Mod8-part21 Conditionals – part 2 Edge Detection Barb Ericson Georgia Institute of Technology May 2007.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops part 3
Declaring Variables – Mod 4
Topic 10 The if statement Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Barb Ericson Georgia Institute of Technology Dec 2009
Barb Ericson Georgia Institute of Technology August 2005
Barb Ericson Georgia Institute of Technology August 2005
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 1
Barb Ericson Georgia Institute of Technology August 2005
Manipulating Pictures, Arrays, and Loops part 5
Two-Dimensional Arrays and Nested Loops – part 1
Georgia Institute of Technology
Workshop for Programming And Systems Management Teachers
Declaring Variables – Mod 4
Manipulating Pictures, Arrays, and Loops part 3
Introduction to Media Computation
Introduction to Processing Digital Sounds part 3
Barb Ericson Georgia Institute of Technology Oct 2005
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 2
Workshop for Programming And Systems Management Teachers
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 6
CSC1401 Viewing a picture as a 2D image - 2
Barb Ericson Georgia Institute of Technology May 2006
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology Oct 2005
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

Barb Ericson Georgia Institute of Technology August 2005 Conditionals - part 1 Barb Ericson Georgia Institute of Technology August 2005 Georgia Institute of Technology

Georgia Institute of Technology Learning Goals Understand at a conceptual and practical level How to conditionally execute a statement or a block of statements How to remove red-eye from a picture Georgia Institute of Technology

Georgia Institute of Technology 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 See http://science.howstuffworks.com/question51.htm for more information on red-eye. Georgia Institute of Technology

Georgia Institute of Technology Red Eye Algorithm We can find the area around the eyes to limit where we change the colors Using pictureObj.explore() But we still just want to change the pixels that are “close to” red. We can 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 Georgia Institute of Technology

Detailed Red Eye Algorithm Loop with x staring at some passed start value and while it is less than some passed end value Loop with y starting at some passed start value and while it is less than some passed end value 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) change the color to some passed new color Georgia Institute of Technology

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 Java if (colorDistance < value) Statement or block to execute next statement false if (expression) true Statement or block Use indentation to make your code easier for other people to read. It doesn’t matter to the compiler. Remember that a block of statements in Java is inside {}. statement Georgia Institute of Technology

Georgia Institute of Technology Using if Exercise Open DrJava and try this in the interactions pane int x = 2; if (x > 1) System.out.println(“X is > 1”); System.out.println(“X is “ + x); x = 0; Georgia Institute of Technology

Georgia Institute of Technology Blocks of Statements The if statement will conditionally execute the following statement or A block of statements if the test is true To conditionally execute a block of statements Enclose them in ‘{‘ and ‘}’ Indent the following statement or block of statements To make it easier to read It is good practice to always enclose conditional statements in a block Less likely to cause an error if the code is modified Georgia Institute of Technology

Georgia Institute of Technology 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 double dist = pixelObj.colorDistance(color1); Georgia Institute of Technology

Georgia Institute of Technology 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); Georgia Institute of Technology

Georgia Institute of Technology Remove Red Eye Method // if the color is near red then change it if (pixelObj.colorDistance(Color.red) < 167) { pixelObj.setColor(newColor); } You don’t have to enclose the pixelObj.setColor statement in a block since it is just one statement but it makes the good easier to read and maintain. Georgia Institute of Technology

Georgia Institute of Technology Testing removeRedEye String file = FileChooser.getMediaPath(“jenny-red.jpg”); Picture p = new Picture(file); p.explore(); p.removeRedEye(); Georgia Institute of Technology

Georgia Institute of Technology Challenge Take a picture of a friend And try to change their eye color Try to change their hair color Try to change their clothing color Can you write one method to do this? And call it several times with different parameters? Georgia Institute of Technology

Georgia Institute of Technology Summary Use the if statement to conditionally execute another statement or a block of statements if (boolean test) statement { // statements to execute if the test is true } Georgia Institute of Technology