CPSC120 Lab 11

Image Processing

  1. Green Screen

    Create a program called green_screen.py that composites an image taken with a green screen and a background image. A green screen image has a mostly uniform bright green background. When a green screen image is composited with another image all bright green pixels in the green screen image are replaced with the pixels at the same location in the other image. Note that not all bright green pixels are going to have the same RGB values. So all pixels that are near bright green (R, G, B) = (0, 255, 0) should be replaced. A pixel should be considered near bright green if the red is near zero, the green is near 255 and the blue is near 0. In order to produce a good composite, you will have to adjust the threshold for what is considered near.

    Test your program on some hand-created 2 x 2 images. Once it is working, test it on some actual images. Do a google image search for a green screen image and for a background image. The background image should have both a width and a height that are larger than the green screen image. Save the images to your lab directory and convert the images to pnm images using the Linux command line programs (jpegtopnm, giftopnm, etc.) and use the pnmtoppm.py Python script to convert the pnm files to ppm files. Import the ppm.py module to read and write the image files.

  2. Steganography

    Create a program called steganography.py that prints the secret message that is embedded in an image file specified as a command line argument. The message is encoded in the least significant bits of the image’s red channel in row-major order. The message can be extracted by performing the following operations:

    1. Create a list of the image’s red values in row-major order.

    2. Convert each red value to a binary string using the built-in function bin.

    3. Trim each binary string to only its least significant bit.

    4. Concatenate each sequential group of 1 bit strings into 8 bit strings.

    5. Convert each 8-bit string to an int using the built-in function int.

    6. Convert each int into a character using the built-in function chr.

    7. Concatenate all of the characters together using the string method join.

    You can assume the total number of pixels in the imput image is a multiple of 8. Test your program on a small hand-created 8 x 2 image that encodes just two letters. Once it is working, test it on th larger image landscape.ppm.


Submit a zip file of your code on the course Inquire site that uses your last names as the file name.