Use the command line to create a new directory called lab28 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.
Image files can be thought of as just 2-dimensional lists of pixel color values. We can even extend that thought to 3-dimensional lists, since every pixel value can be represented by a red, green, and blue values (typically abbreviated RGB). The one complexity with this representation is how to get an image file into a list of this structure. Luckily, we are giving you a module that will do just that.
The ppm.py module
holds 4 functions, but you are only concerned with two of them.
the read_image(file_name)
function takes a string file
name of a PPM image, and returns a 3-dimensional list of pixel color
values. For any given pixel color list, the red value is store in
the 0th index, the green value is stored in the
1st index, and the blue value is stored in the
2nd index.
The write_image(ppm_file_name, image)
takes a string
file name of where you want to write a PPM image, and a
3-dimensional list of the above form. This function will actually
write the image out to the file system, using the file name
specified in the parameters.
Blurring is a frequently used in fashion photography to smooth skin. In this activity you will create a miniature photoshop that can blur images.
Details
Create a function called blur_image(input_image_name,
output_image_name)
in a file called blur.py. The
function should load the image in the
file input_image_name
, blur the image, and save the
image to a file called output_image_name
. You can blur
a pixel by taking the average of the pixel's neighbors. A pixel's
neighbor's are the pixels above, below, left, and right of a pixel.
You can blur the image by blurring all of the pixels.
Example
The following image on the right is the result of blurring the image on the left ten times.

Hint
Challenge
You can produce blurred images that better mimic a camera lens blur by using a Gaussian function to compute a weighted average. Compute a Gaussian blur by summing the result of multiplying each pixel in a 5x5 grid with the following weights.
1/273 | 4/273 | 7/273 | 4/273 | 1/273 |
4/273 | 16/273 | 26/273 | 16/273 | 4/273 |
7/273 | 26/273 | 41/273 | 26/273 | 7/273 |
4/273 | 16/273 | 26/273 | 16/273 | 4/273 |
1/273 | 4/273 | 7/273 | 4/273 | 1/273 |
It is pretty expensive to film movies and TV shows on location now-a-days. However, with a little bit of Movie Magic, we can pretend to be anywhere in the world. Ever want to pretend you traveled to the expanses of Moscow? Now is your chance! Ever want to go to Delaware? Yeah… Delaware.
Use Google image search to find a green screen image, and a background image that is at least the same size, if not larger. You are going to write a program that will take these two images, and composite them together to create one image. You will need to convert these pictures to PPM files, as demonstrated in class.
Details
Write a function overlay_greenscreen(greenscreen_list,
background_list)
in a file called greenscreen.py.
This function takes two parameters: an m ×
n 2-dimensional list of RGB values (really just a
3-dimensional list of integers), and a j ×
k 2-dimensional list of RGB values (but really just a
3-dimensional list of integers), where j ≥
m and k ≥ n. This function
should modify greenscreen_list by replacing pixels that are
mostly green, with the corresponding pixel
from background_list.
As it turns out, it's really hard to get a green screen to be exactly green. Thus, it is not sufficient to check just the value of the green portion of a given pixel. You need to make sure the green value is high enough, and that the red and blue values are low enough to make sure the color is truly "green."
Example
Here is a very simplistic example of what you are trying to do:
+
=
Hint
Challenge
It's one thing to use a green screen image you found on the Internet. It's another thing entirely to make your own green screen images! Luckily, we have this nice (hopefully pretty clean) chalkboard that we could you to mimic a green screen.
Take a picture with your cellphone (or a friends) of yourself standing in front of the chalkboard. Email the picture to yourself, and try to composite your image with a different image you found on the web. You will likely have to make drastic changes to your threshold values, but you should be able to get somethin
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.