Download presentation
Presentation is loading. Please wait.
1
Multimedia Summer Camp
Using Loop for Pictures
2
For-loop A for loop executes some commands (that you specify) for a sequence (that you provide) Each time the commands are executed, a particular variable (that you name) will have the value of a different element of the sequence. A sequence is an ordered collection of data.
3
For-loop syntax: for variable_you_named in sequence_you_provided :
a_block_of_commands_you_specified
4
Example def decreaseRed(picture): for p in getPixels(picture):
value = getRed(p) setRed(p, value*0.5) p is the name of the variable getPixels is a function provided by Jython to return the sequence of Pixel objects in the given picture. Last two statements are commands to be executed for each pixel in the picture
5
Example Once we make it work for one picture, it will work for any picture.
6
What if you decrease Santa’s red again and again and again…?
7
Increase Red What happened here?!?
Remember that the limit for redness is 255. If you could go beyond 255, all kinds of weird things can happen
8
Increase Red Remember that the limit for redness is 255.
So even if you try to go beyond 255, JES will set the level to 255 max. These blotches won’t happen :)
9
How does increaseRed differ from decreaseRed?
Well, it does increase rather than decrease red, but other than that… It takes the same parameter input It can also work for any picture It’s a specification of a process that’ll work for any picture There’s nothing specific to any particular picture here.
10
Clearing Blue Again, this will work for any picture.
Try stepping through this one yourself!
11
Can we combine these? Why not!
How do we turn this beach scene into a sunset? What happens at sunset? At first, I tried increasing the red, but that made things like red specks in the sand REALLY prominent. That can’t be how it really works New Theory: As the sun sets, less blue and green is visible, which makes things look more red.
12
A Sunset-generation Function
13
Creating a negative A positive image is a normal image.
A negative image is a total inversion of a positive image, in which light areas appear dark and vice versa. Let’s think it through R, G, B go from 0 (low) to 255 (high) Let’s say Red is 10. That’s very light red. What’s the opposite? LOTS of Red! The negative of that would be 245: So, for each pixel, if we negate each color component in creating a new color, we negate the whole picture.
14
Creating a negative
15
Original, negative, double negative
This gives us a quick way to test our function: Call it twice and see if the result is equivalent to the original
16
Converting to grayscale
When red=green=blue then the color is a shade of gray But what value do we set all three to? What we need is a value representing the darkness of the color, the luminance Simple way is to take the average of R, G, B:
17
Converting to grayscale
18
Why can’t we get back again?
Converting to a negative is reversible. A negative transformation retains information. Converting to grayscale is not reversible, we’ve lost information We no longer know what the ratios are between the reds, the greens, and the blues We no longer know any particular value.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.