Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson."— Presentation transcript:

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

2 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

3 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

4 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.

5 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

6 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!

7 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();

8 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

9 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? 255 - x

10 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

11 ManipulatingPictures-Mod6-part611 Negate Method

12 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 (15 + 25 + 230) / 3 = 90

13 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

14 ManipulatingPictures-Mod6-part614 Grayscale Method

15 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

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

17 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)

18 ManipulatingPictures-Mod6-part618 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) The value needs to be a whole number (integer) but the equation creates a floating point number (double)

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

20 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, 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


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

Similar presentations


Ads by Google