This is a lab exercise that involves writing code that manipulates an image and displays it on the screen. Again I am strongly encouraging you to work on this lab in pairs.
I am strongly encouraging you to work on this assignment with another student. If you choose to work as a team, you must do the entire project together and you must contribute equally. When you submit your program, only submit it once (using either of your Truman usernames), but be sure to include both names in comments in the file.
For this part of the lab I want you to start with my version of the class negative code negative.py.
Try this code out on the image files lutherBell.gif and earth.gif. To try it out, type:
makeNegative("earth.gif")
then try to find and display the graphics window that is created.
In this same file, type in the grayPixel function from class, which is:
def grayPixel(oldpixel):
intensitySum = oldpixel.getRed()+oldpixel.getGreen()+oldpixel.getBlue()
aveRGB = intensitySum // 3
newPixel = Pixel(aveRGB,aveRGB,aveRGB)
return newPixel
As we did in class on Monday, rename makeNegative
to changeImage
and modify it to take
a pixelChanger
function as a parameter. Instead of
calling the specific negativePixel
function,
your changeImage
should call this parameterized value.
Try calling changeImage
with negativePixel and with
grayPixel to make sure it works.
For your lab assignment, you need to define a function called
sepiaPixel
to give the image that old-timey Western kind
of look. Define this function in the same file as your functions
from above.
The beginning of a formula for calculating sepia tones is:
newRed = (R*0.393) + (G*0.769) + (B*0.189)
newGreen = (R*0.349) + (G*0.686) + (B*0.168)
newBlue = (R*0.272) + (G*0.534) + (B*0.131)
But note that there are two issues with these formulas. One is that
the RGB values should be integers. The other is that sometimes these
formulas will give values that are greater than 255. So, you need to
come up with a sepiaPixel
function that takes an input
pixel and returns a sepia-toned pixel that has integer RGB values in
the range 0-255. Try your sepiaPixel
function by
passing it as a parameter to your changeImage
function.
A particularly apt file for trying out sepia is OldCoots.gif.
This lab is due Thursday, November 15. When you are convinced that your code is correct, well-documented and your name is in the file, upload the file.