Manipulating Pictures, Arrays, and Loops part 6

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.
Georgia Institute of Technology Movies part 3 Barb Ericson Georgia Institute of Technology April 2006.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
ManipulatingPictures-Mod6-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
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.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 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.
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.
TOPIC 10 THE IF STATEMENT 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
Conditionals-Mod8-part21 Conditionals – part 2 Edge Detection Barb Ericson Georgia Institute of Technology May 2007.
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.
Barbara Ericson Georgia Tech Sept 2005
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Topic 6 Modifying Pictures Using Loops
Barb Ericson Georgia Institute of Technology Dec 2009
Manipulating Pictures, Arrays, and Loops part 3
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 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
Barb Ericson Georgia Institute of Technology August 2005
Two-Dimensional Arrays and Nested Loops – part 1
Barb Ericson Georgia Institute of Technology August 2005
Workshop for Programming And Systems Management Teachers
Introduction to Processing Digital Sounds part 2
Manipulating Pictures, Arrays, and Loops part 5
Two-Dimensional Arrays and Nested Loops – part 1
Manipulating Pictures, Arrays, and Loops part 4
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 3
Introduction to Media Computation
Barb Ericson Georgia Institute of Technology June 2006
CSE 113 A February , 2009.
Two-Dimensional Arrays and Nested Loops – part 6
Two-Dimensional Arrays and Nested Loops – part 2
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
February , 2009 CSE 113 B.
Processing Sound Ranges part 2
Manipulating Pictures, Arrays, and Loops part 6
Two-Dimensional Arrays and Nested Loops – part 6
Barb Ericson Georgia Institute of Technology May 2006
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology April 2006
Presentation transcript:

Manipulating Pictures, Arrays, and Loops part 6 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 change all the colors in a method How to use a for loop How to negate a picture How to turn a picture into grayscale How to adjust the grayscale based on how we perceive colors Georgia Institute of Technology

Georgia Institute of Technology Negating an Image How would you turn a picture into a negative? White should become black 255,255,255 becomes 0,0,0 Black should become white 0,0,0 becomes 255,255,255 Georgia Institute of Technology

Georgia Institute of Technology Negate Algorithm Subtract current value from 255 for red, green, and blue Get the array of pixels from the picture Declare variables to hold the current pixel and the red, green, and blue values Loop starting an index at 0 and incrementing by 1 and loop while the index is less than the length of the array Get the pixel at the current index from the array of pixels Set the red value to 255 – current red value Set the blue value to 255 – current blue value Set the green value to 255 – current green value Increment the index and go back to step 3 Georgia Institute of Technology

Georgia Institute of Technology Negate Method /** * Method to negate the picture */ public void negate() { Pixel[] pixelArray = this.getPixels(); Pixel pixelObj = null; int redValue, blueValue, greenValue = 0; // loop through all the pixels for (int i = 0; i < pixelArray.length; i++) { // get the current pixel pixelObj = pixelArray[i]; // get the values redValue = pixelObj.getRed(); greenValue = pixelObj.getGreen(); blueValue = pixelObj.getBlue(); // set the pixel's color pixelObj.setColor( new Color(255 - redValue, 255 - greenValue, 255 - blueValue)); } Georgia Institute of Technology

Georgia Institute of Technology Changing to Grayscale Grayscale ranges from black to white The red, green, and blue values are the same How can we change any color to gray? What number can we use for all three values? The intensity of the color We can average the colors (red + green + blue) / 3 Example (15 + 25 + 230) / 3 = 90 To average x numbers get the sum of all the numbers and then divide by x. Georgia Institute of Technology

Georgia Institute of Technology Grayscale Algorithm Set color values to the average of the original values Get the array of pixels from the picture Declare variables to hold the current pixel and the red, green, and blue values Loop starting an index at 0 and incrementing by 1 and loop while the index is less than the length of the array Get the pixel at the current index from the array of pixels Calculate the average of the current values (redValue + greenValue + blueValue )/ 3 Set the red value to the average Set the blue value to the average Set the green value to the average Increment the index and go to step 3 Georgia Institute of Technology

Georgia Institute of Technology Grayscale Method /** * Method to change the picture to gray scale */ public void grayscale() { Pixel[] pixelArray = this.getPixels(); Pixel pixelObj = null; int intensity = 0; // loop through all the pixels for (int i = 0; i < pixelArray.length; i++) { // get the current pixel pixelObj = pixelArray[i]; // compute the average intensity intensity = (pixelObj.getRed() + pixelObj.getGreen() + pixelObj.getBlue()) / 3; // set the pixel color pixelObj.setColor(new Color(intensity,intensity,intensity)); } Georgia Institute of Technology

Georgia Institute of Technology Testing Grayscale String file = “c:/intro-prog-java/mediasources/caterpillar.jpg”; Picture pictureObj = new Picture(file); pictureObj.explore(); pictureObj.grayscale(); Georgia Institute of Technology

Georgia Institute of Technology Grayscale Result Georgia Institute of Technology

Georgia Institute of Technology Luminance We perceive blue to be darker than red, and green Even when the same amount of light is reflected A better grayscale model should take this into account Weight green the highest (* 0.587) red less (* 0.299) and blue the very least (* 0.114) Georgia Institute of Technology

Grayscale with Luminance Exercise Create a new method grayscaleWithLuminance Using the new algorithm for calculating intensity intensity = (int) (red * 0.299 + green * 0.587 + blue * 0.114) Georgia Institute of Technology

Testing Grayscale with Luminance String file = “c:/intro-prog-java/mediasources/caterpillar.jpg”; Picture pictureObj = new Picture(file); pictureObj.explore(); pictureObj.grayscaleWithLuminance(); Georgia Institute of Technology

Georgia Institute of Technology Summary You can change all the colors in a method By creating a new color object You can negate a picture By creating a new color with (255 - red, 255 - green, 255 - blue) You can create a grayscale picture By setting the red, green, and blue to the same value You can improve this by weighting the colors based on how we perceive them Georgia Institute of Technology