In this project, you will learn how a computer can modify images. You will be programming transformations similar to those built into programs like Photoshop.
You may choose to do this project with a partner. If you choose to work with a partner, Please only submit one copy of the code with both names written in image.py as comments
If the image is big, try to reduce the size before saving. You can go to Tools -> Adjust Size to change the size of the image
sepiaTone. Regarding the hint in that exercise, first think about how you would convert the RGB values to integers. Then think about how you would make sure each value is no larger than 255, using the min function.
Ynew = (Yold)gamma
However, pixels in our images are in RGB, not in YUV. The following formulas will help you convert between RGB and YUV values.
Y = 0.00117 * R + 0.00230 * G + 0.000447 * B
U = -0.000577 * R - 0.00113 * G + 0.00171 * B
V = 0.00241 * R - 0.00202 * G - 0.00039 * B
Ynew = (Yold)gamma
R = 255 * (Y + 1.13983 * V)
G = 255 * (Y - 0.39465 * U - 0.58060 * V)
B = 255 * (Y + 2.03211 * U)
Modify the RGB values if necessary to make them no smaller than 0 and no larger than 255.
gammaTwo that takes a pixel and performs a gamma correction with the gamma value of 2.0.
gammaHalf that takes a pixel and performs a gamma correction with the gamma value of 0.5.
gammaHalf and gammaTwo. What you need to do is create a third function called gammaN which takes in a pixel object and a number. This third function should then be called by both gammaHalf and gammaTwo.
transformPixels that takes an image and a procedure that transforms a pixel and returns a new image with all the original pixels transformed by the given procedure.
rotateImage90 that takes an image and returns an image of the original image rotated 90 degrees clockwise.drawImages that takes a title and a list of images and draws the images on a new canvas. The images will be drawn onto the canvas side-by-side horizontally with 1-pixel-wide gaps. Make sure the canvas is just wide and tall enough (not unnecessarily big) and the title is shown correctly. Also, make sure the window closes on a mouse click.
Assume darkKnight refers to the following image object:
>>> darkKnight = FileImage("dark.knight.gif")
>>> drawImages("Dark Knight", [transformPixels(darkKnight, gammaHalf), transformPixels(rotateImage90(darkKnight), gammaTwo)])
should show the following window.
Assume princessBride refers to the following image object:
>>> princessBride = FileImage("princess.bride.gif")
>>> drawImages("Princess Bride", [princessBride, rotateImage90(rotateImage90(princessBride))])
should show the following window.
The words "princess bride" look the same in the two images because this is an ambigram for the cover of the 20th anniversary edition of Princess Bride.
drawImages.
You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following file:
You will earn one point for each of the following accomplishments:
sepiaTone.
sepiaTone correctly applies sepia tone.
sepiaTone uses min function.
gammaTwo.
gammaHalf correctly applies the gamma correction with 2
gammaHalf.
gammaHalf correctly applies the gamma correction with 0.5
gammaHalf and gammaTwo do not repeat codes.
transformPixels.
transformPixels applies the transform procedure to all the pixels in the given image.
rotateImage90.
rotateImage90 rotates the image 90 degrees clockwise correctly.
drawImages.
drawImages places the title for the image window.
drawImages calculates the correct width and height for the image window.
drawImages places images at the right positions with gaps inbetween them.
drawImages can place an arbitrary number of images.