Section 21.5 Increasing and decreasing brightness
While using this recipe, we can change one color channel (red/green/blue) at a time, or we can change all three. If we increase the value of all colors, we make the image brighter. If we decrease all the colors, we make the image darker.
This program uses step five to increase each color value by 50% (1.5 times its original value.)
Try decreasing each color channel by 50% (make it 0.5 times its original value) - you should end up with a darker version of the same picture.
Checkpoint 21.5.1.
If we want to make the image both brighter and more red, we could increase just the red value. However, if we want it to look more red, but not get brighter overall, we would want to make a small increase to the red value and a small decrease in the blue and green values.
Arrange and indent the blocks below to make a recipe that would make the image redder but not increase the overall brightness much. You should modify the red value before you modify the green & blue (that would not matter in a real program, but here you need to have them in that order.)
from image import *
---
img = Image("cat.jpg")
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
---
pixels = img.getPixels()
for p in pixels:
---
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
---
p.setRed(g * 1.2)
---
p.setRed(g * 0.9) #paired
---
p.setGreen(g * 0.9)
p.setBlue(b * 0.9)
---
p.setGreen(g * 1.2)
p.setBlue(b * 1.2) #paired
---
img.updatePixel(p)
You have attempted
of
activities on this page.