ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.

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 Manipulating Pictures, Arrays, and Loops part 1.
DIGITAL IMAGE PROCESSING CMSC 150: Lecture 14. Conventional Cameras  Entirely chemical and mechanical processes  Film: records a chemical record of.
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.
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.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Pictures Looping through pixels.. Lab Review (1) Objects  Instantiated from Class  Turtle myTut = new Turtle(myWorld);  new operator creates an instance.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
ManipulatingPictures-Mod6-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology.
Homework Assignment You are going to research any artist of your choosing from any time period or genre. You are going to complete a one page double- spaced.
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.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Conditionals-part41 Conditionals – part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
Conditionals-Mod8-part41 Conditionals – part 4 Replace background Barb Ericson Georgia Institute of Technology May 2007.
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,
CS 101 – Sept. 14 Review Huffman code Image representation –B/W and color schemes –File size issues.
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
CS1315: Introduction to Media Computation Using Loops for Pictures.
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.
CS 101: Introduction to Computing Programs that change Pictures Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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.
TOPIC 8 MORE ON WHILE LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 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,
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
Manipulating Pictures, Arrays, and Loops part 5
Two-Dimensional Arrays and Nested Loops – part 1
Workshop for Programming And Systems Management Teachers
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
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
What Color is it?.
Processing Sound Ranges part 2
Manipulating Pictures, Arrays, and Loops part 6
Barb Ericson Georgia Institute of Technology May 2006
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology April 2006
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson Georgia Institute of Technology

ManipulatingPictures-Mod6-part62 Learning Goals –Eliminate a single tone –Negate a picture –Turn a picture into grayscale –Adjust the grayscale based on how we perceive colors

ManipulatingPictures-Mod6-part63 Clear all of one color What if you want to clear the blue from a picture? –Set all the blue values to 0 for all the pixels The algorithm is similar to decreaseRed() and increaseRed() except –You don’t need to get the value out for blue and multiply it by some value and then set the blue value –Just set the blue value to 0 –So you can use a for each to go through every pixel

ManipulatingPictures-Mod6-part64 Clear Blue Method /** * Remove blue */ public void clearBlue() { Pixel[ ] allDots= this.getPixels(); for(Pixel p: allDots){ p.setBlue(0); } } Notice that the names of the variables can be any valid name you choose.

ManipulatingPictures-Mod6-part65 What happens to the color white when one of the 3 colors is removed? White = (255,255,255) Take away the red and you get (0,255,255) Turquoise Take away the green and you get (255,0,255) Purple Take away the blue and you get (255,255,0) Yellow

ManipulatingPictures-Mod6-part66 Clear Blue or Green Exercise Put your code in Picture.java Change the clearBlue() method and write the clearGreen() method –public void clearGreen() That sets the green value to 0 for all pixels in a picture This is clearBlue You are making clearGreen!

ManipulatingPictures-Mod6-part67 How will you test your methods? Test with a test class: public class testMethod{ public static void main(){ String fileName = “dogs-garden.jpg”; Picture p = new Picture(fileName); p.explore(); p.clearGreen(); p.explore(); } } Or Test with the code pad: Picture p = new Picture(“dogs-garden.jpg”); p.explore(); p.clearGreen(); p.explore();

ManipulatingPictures-Mod6-part68 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

ManipulatingPictures-Mod6-part69 What about numbers in between black and white? All color values go from 0 to 255 –10 should become:______ 245 –200 should become: ______ 55 –What is the equation if x is the color value? x

ManipulatingPictures-Mod6-part610 Negate Algorithm 1.Get the array of pixels from the picture 2.Declare variables to hold the red, green, and blue values 3.Loop through all pixels 4.Get the pixel at the current index from the array of pixels 1.Set the red value to 255 – current red value 2.Set the blue value to 255 – current blue value 3.Set the green value to 255 – current green value

ManipulatingPictures-Mod6-part611 Negate Method

ManipulatingPictures-Mod6-part612 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 ( ) / 3 = 90

ManipulatingPictures-Mod6-part613 Grayscale Algorithm Set color values to the average of the original values 1.Get the array of pixels from the picture 2.Declare variables to hold the red, green, and blue values 3.Loop through all the pixels in the array 1.Calculate the average of the current values (redValue + greenValue + blueValue )/ 3 2.Set the red value to the average 3.Set the blue value to the average 4.Set the green value to the average

ManipulatingPictures-Mod6-part614 Grayscale Method

ManipulatingPictures-Mod6-part615 Testing Grayscale on the caterpillar Picture pictureObj = new Picture( “caterpillar.jpg” ); pictureObj.explore(); pictureObj.grayscale(); pictureObj.explore(); Type this in the codepad or create a new class with a main method to test it

ManipulatingPictures-Mod6-part616 Grayscale Result Color is too flat, doesn’t look like the same colors

ManipulatingPictures-Mod6-part617 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)

ManipulatingPictures-Mod6-part618 Grayscale with Luminance Exercise Create a new method grayscaleWithLuminance Using the new algorithm for calculating intensity intensity = (int) (red * green * blue * 0.114) The value needs to be a whole number (integer) but the equation creates a floating point number (double)

ManipulatingPictures-Mod6-part619 Testing Grayscale with Luminance Picture pictureObj = new Picture( “caterpillar.jpg” ); pictureObj.explore(); pictureObj. grayscale (); pictureObj.explore();

ManipulatingPictures-Mod6-part620 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, green, 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