< Back

Lab 10: Images


Greyscale

In a file called grey.py, write a function called compute_greyscale(picture). This function should alter the pixels stored inside of the picture object, so that all three pixel values are averaged and set to that average. Your function should then display the greyscale picture.

Example

Before After

Hint

Use the makePicture function to create a picture in JES. You can use the show function to display the image to check to make sure it works.

The getPixels(a_picture) function returns a collection of all of the pixels in an image. You can use this function, as well as a for loop to examine and modify each pixel in an image.

The getRed, getGreen, and getBlue functions will give you the current color of a pixel.

The setRed, setGreen, and setBlue functions will let you set the color of a pixel.

You can compute the average value by adding the red, green, and blue values, and dividing by 3.


Photo Negative

In a file called negative.py, write a function called compute_negative(picture). This function should alter the pixels stored inside of the picture object, so that all three pixel values are their negated version. Your function should then display the negative picture.

Example

Before After

Hint

To make a picture the photo negative, you want to "invert" each of the red, green, and blue values. You can accomplish this by simply subtracting the current pixel's color value from 255.

You may wish to write 3 additional functions for this activity: negate_red, negate_green, and negate_blue. These functions simply negate each of the color values for each pixel separately. Then you just call these functions in your negate.