imagegram.py: 38 points
Now, you will implement two functions that modify the image, described below. You will not need to make a copy of the image for these functions: simply loop over the original image, changing the pixels as you go. For more information about how to use the picture module to modify an image, please refer to the documentation. All of the variables you use in your functions should be local, not global, variables.
picture module provides two methods for displaying an image to the screen—
picture.display(). Until now, you’ve only been using
picture.run(). This function displays the current image and then keeps your program running until the image window is closed. This is useful when you want to display an image once. What if you want to update an image while your program is running? In that case, you’ll need to use
picture.display(). This function creates or updates an image window with the current image. However, the image window will close as soon as your program ends. Since your
imagegram.py program will use a
while loop to monitor the user’s input, you should use
picture.display() whenever you want to show the user the current version of their image.
The negative of an image is created by inverting each color channel. So if the red value of a pixel were 255, it should become 0. If it were 254, it should become 1, and so on, down to 0 (which should become 255). Similarly for green and blue.
Shades of gray have the same red, green, and blue value. To convert an image to grayscale, you should set the red, green, and blue values all to the average value of the three channels of the original pixel. This filter is identical to the grayscale filter you designed in the warmup.
Once you’ve implemented a function, add the ability to call it from your looping menu and make sure to test it!