170 likes | 176 Views
Learn how to replace colors, reduce red-eye, create sepia-toned pictures, and perform edge detection in this multimedia summer camp.
E N D
Multimedia Summer Camp Replacing Colors: Red-Eye, Sepia Tones
Outline • Replacing colors with another color broadly or just within a range • Reducing red-eye • Sepia-Toned Pictures • Edge detection
Reducing Red-Eye • If you use a flash in a dark environment, you often get a red eye effect. This is because the light of the flash is reflecting from the retina, which is covered with tiny blood vessels.
Reducing Red-Eye • Initial solution • Scan the picture pixel by pixel, replace each pixel whose color is close enough to red by black. • Problem • This will also change the color of the kid’s cloth.
Reducing Red-Eye • Better solution • Find the range of where the eyes are red • Scan the range pixel by pixel, replace each pixel whose color is close enough to red by black
Reducing Red-Eye • Find the range of where the eyes are red • Open the picture by typing the following command in the command area: openPictureTool( makePicture( pickAFile() ) ) • Click at the upper left corner of her eyes, the x- and y-coordinates will show up • x: 112, y: 87 • Click at the lower right corner of her eyes, the x- and y-coordinates will show up • x: 199, y: 106
Reducing Red-Eye • How to check if a pixel’s color is close enough to red • distance(color1, color2) Takes two Color objects and returns a single number representing the distance between the colors.
Reducing Red-Eye • We need a way to tell Jython to make decisions based on a test. • In this case, if “a pixel’s color is close enough to red”, ask Jython to “change its color to black”. • Jython provides if-statement for this purposes • syntax: if <test>: <actions_to_be_done> • meaning: if the test is true, perform the specified actions. if the test is false, ignore the specified actions. • We can test on: <. >, == (for equality), != (for inequality, not-equals) and even <=, >=.
Reducing Red-Eye • The function takes a lot of inputs so that it can be useful for many different pictures. • Jython provides some color constants such as: red, black, green, yellow, blue. • We determine “close enough” by looking for a distance within a threshold value. We have tried different distances, and settled on 165.
Sepia-Toned Pictures • Sepia tone used to be known as the natural process that overtook older photographs as they faded into the obscurity of age. • Just like a newspaper article left in archives, photographs go through a similar process over the years that give them a brownish hue.
Sepia-Toned Pictures • Solution • Convert the picture to grayscale because older prints were in a grayscale, and it makes it a little easier to work with. • A better grayscale function will be used • Look for high and low ranges of color (really, luminance), and change them separately.
Sepia-Toned Pictures • Why these particular values in this function? • Trial and error – tweaking them until we liked the effect
Sepia-Toned Pictures Original Picture Sepia-Toned Picture Grayscaled Picture
Edge Detection • Edge detection is a process to compare pixels to determine what to put in a given pixel, either black or white • Compare each pixel’s luminance to the pixel below it and to the right of it. • If there is a suitable difference, make the pixel black, otherwise, make it white. • The idea is to try to draw lines the way an artist might sketch a drawing with lines.