
In this project, you will arrange your filtered versions of an image in the style of Andy Warhol within a 2x2 grid. You will also create an "image filter" to remove the green background of a green screen photo that you will take over Zoom and place yourself inside another image of an exotic beach. You will use lists to organize which image goes where in your grid.
Make at least 3 more Instagram-style filters. Take a look at Andy Warhol's screen prints and have at least 1 of your filters be based on one of his prints. Be creative! You need to do more than simply swap color combinations — there are lots of possibilities!
In your report section called Art Reflection discuss which composition inspired you and what aspects of the compositions you emulated.
Take a screenshot of each filter applied separately to one image of your choice. Collectively, this is Required Image 1 in your project.
Update your main code in filters.py to only call your test function.
Allow the user to pass in a second command-line argument to filters.py, which is a string that can be used to check which of one of your image filters should be applied to the image. Be sure to pass it as an function parameter to test and add code to check which filter to apply.
Here is an example of showing the image miller.ppm after it has been processed with the swapGreenBlue filter. The resulting image should be saved in your project folder as a PPM file.
python3 filters.py miller.ppm swapGreenBlue
You could use none or original to indicate leaving the image alone / not applying any filter.
filters.py and show.pyImagine giving filters.py or show.py to a friend and they tried to run your code. The program would crash with a unhelpful error message because they don't know that they need to pass in the image filename as a command-line argument (try it!). Frustrating!
From now on, you will be expected to print a proper usage statement if your program uses command-line arguments (so that the user knows how to run your program!).
In both filters.py and show.py, check the number of command-line arguments that the user passes in. If the user does not pass in enough command-line arguments, print out how to run your code without crashing. Here is a good example:
Usage: python3 show.py <filename of image>
Call the exit function right after printing out the message to stop the program cleanly without crashing.
Test running filters.py and show.py with the correct and incorrect number of command-line arguments. For example, running show.py:
In this task, you will use Zoom to take a photo of yourself with your real-life background replaced with a solid green color (like what TV anchors use on set). Then you will create a Python program that replaces the green screen background with another image (e.g. an exotic beach scene with palm trees is provided).
The Zelle graphics library can open only PPM format images, not PNG (or JPG) files, which are more common types of images. You can convert a PNG file to a PPM file using a Terminal program called ImageMagick.
Installing ImageMagick on your computer is optional, but attempting to do so is recommended (helpful for extensions, filtering your own images, etc.). Please do not spend more than 30 minutes trying to install it. Please see the work-arounds below.
Follow the ImageMagick installation instructions for macOS and Windows.
(If you could not install ImageMagick on your computer, download the the exotic beach scene in PPM format and move to Task 2c)
Download the exotic beach scene in PNG format to your Project 6 folder.
In Terminal, change directories to your Project 6 folder. Then run the following command:
convert exotic.png exotic.ppm
You should see exotic.ppm (a new file) appear in your Project 6 folder. Take a look at exotic.ppm to make sure that it looks like the corresponding PNG file (e.g. open it in Finder or using your show.py).
Download this solid green background.
Open the Zoom app on your computer and click "New Meeting" on the main app screen. You should now see yourself on video.
Open Zoom preferences in the app. On macOS, this can be accessed by clicking on zoom.us in the menubar (top left of your screen, next to the apple icon) then clicking Preferences....
Click on Background & Filters, then click the + button (see below) and select Add Image. Select the green background that you downloaded above. You should now see yourself in front of a green screen! Take a screenshot.
Tip: It will look best if you make your screenshot roughly square. You do not need to precisely measure, any rectangle will work. This is because the image that you will be replacing the green background with, exotic.ppm, is a square image.

Rename the screenshot that you took of yourself myGreenScreen.png. Move it to your Project 6 folder. Make sure that Terminal is also in your Project 6 folder.
Run the following Terminal command to convert your green screen image from PNG to PPM format. For macOS users:
convert myGreenScreen.png -resize 512x512\! myGreenScreen.ppm
and for Windows users:
magick myGreenScreen.png -resize 512x512\! myGreenScreen.ppm
You should see myGreenScreen.ppm appear in your Project 6 folder. Verify that the image looks correct (e.g. open it in Finder or using your show.py).
If you could not install ImageMagick on your computer, email me with your Zoom green screen image attached. Please include "PPM" in your email subject so that I instantly know what to do with your email.
Write the function that will replace the green background in your green screen image with another image, a photo of an exotic beach scene (exotic.ppm). You can think of the background replacement process as applying a special kind of filter to your green screen image:
Make a greenscreen filter function in filters.py with the following signature:
def greenScreen(greenImg, otherImg): '''If a pixel in `greenImg` is very green, replace it with the corresponding pixel in `otherImg`. A reasonable test for 'very green' is if the green pixel is 1.5 times the blue channel and also bigger than the red pixel. Play around with the 1.5 number to see if you can get better results. '''
where otherImg is the "exotic beach image" object. The function should implement the logic outlined in the above bullet points and docstring.
Create a new file called greenscreen.py. Write a main function that replaces the green background in your green screen image with the exotic background.
Save a PPM image of you in the beach scene in your project folder. Take a screenshot; this is Required Image 2 in your project.
For this project you'll be creating an Andy Warhol inspired image as a 2x2 grid, showing of the same image four times. At least 3 of the 4 panels should show filtered versions of the image (see above Flowers example).
Make a new file called warhol.py. In it, create a main function in which you will write code to create your Warhol.
def placeImageInCanvas(canvas, img , topleft_x,topleft_y): '''Place the image `img` into the larger canvas `canvas`. The image `img` should be positioned so that its top-left corner appears at (row , col) = (topleft_row, topleft_col) in the large canvas. NOTE: (0, 0) is the top-left corner. Parameters: ----------- canvas: Image. Larger canvas to place the image on. img: Image. Image to be placed on the canvas. topleft_x: int. x pixel position (column) in `canvas` where the top-left corner of `img` should go topleft_y: int. y pixel position (row) in `canvas` where the top-left corner of `img` should go ''' pass
Use a list of lists to store information about each image in the canvas. Each sublist relates to one of the four images and has four items:
Image objectHere is an example with for two images (the original on the left, the filtered version on the right) shown side-by-side:
imageList = [[0, 0, 'original', img], [img.getWidth(), 0, 'swapGreenBlue', img]]
In each sublist, the first two x and y values are positions of the top-left corner of each image in the canvas. You should use methods to get the x and y placement information — don't hard-code values other than 0). The third value is the filter to use (you can use 'original' or 'none' to indicate that the image should be left alone without being filtered). The last entry is the Image object itself.
Requirement: You should use a list of lists to organize each image and its placement properties for your final Warhol Image.
Save a PPM image of your Warhol in your project folder. Take a screenshot; this is Required Image 3 in your project.
In order to grade your project, we need to be able to run your code and get the same results as you do!
In your project submission ZIP file, please include any PPM images that are needed run your code.
Here is a summary of the expected outputs from each of the source code files that you created:
python3 filters.py <image filename> <filter name>: Display in a new window the image passed in by command-line arguments with the filter applied to it, also passed in by command-line arguments. (see note about command-line arguments below).python3 warhol.py: If the required PPM images in your project folder, it should save a new PPM of your 2x2 Warhol image.python3 greenscreen.py: If your green screen and exotic PPM files are both in your project folder, it should save a new PPM to the project folder with your face placed in the beach scene.If you use command-line arguments in any file, please explain what they are and provide an example way to run your code in either code comments or your report. It is ok to deviate from the suggested command-line arguments, but you need to document how the user should run your code!
Congratulations on completing the core tasks! If your code and report meet the above expectations, you’ve already earned up to 26/30 points for this project.
The remaining 4/30 are a chance for you to earn credit for exploring parts of this project and digging deeper to express your creativity! This is entirely optional; 26/30 is a B and is a perfectly respectable place to stop. Extensions are open-ended and exist to compliment the structured core project. Explore and learn something new that interests you! Concentrating your energy on 1-2 "deep" extensions that challenge you will earn you more points than many small, "shallow" extensions.
You can pick your own topics that interest you. Here are a few examples:
Lab06 folder inside Project06).This section will help you convert your green screen image to PPM format and those of you interested in applying filters to images of your own.
Open up Terminal.
Install Xcode Command Line Tools by entering the following command: xcode-select --install.
Install the Homebrew package manager by copy-pasting the following into the terminal (one long command) then pressing Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Finally, install ImageMagick by running the following Terminal command:
brew install imagemagick
Download and run the installer. As of writing this, the first file ImageMagick-7.0.10-29-Q16-HDRI-x64-dll.exe should work for most people.
The Zelle graphics library can open only PPM format images, not JPGs. JPG and PNG images are the formats for you will need to use for your reports or for web pages. You can change a JPG to a PPM using a program called ImageMagick. You can run ImageMagick to do the conversion via the convert command in the Terminal (you need to install it first — see the next section below):
convert myImage.jpg myImage.ppm
The convert program is a very powerful application for manipulating images. If you want to find out more about it, check out the ImageMagick web site.
You may want to make the images smaller for testing (i.e. your images take too long to process). The following ImageMagick command shrinks an image to 25% the original size.
convert myImage.jpg -scale 25% myImage.ppm
If you want to use your own image instead of the beach scene for your green screen program, the following converts the original image (assuming it is a JPG) to 512x512, which should take a reasonable time to process on your computer (lower the dimensions if your code is taking too long to finish):
convert myImage.jpg -resize 512x512\! mySmallImage.ppm
© 2021 Hannen Wolfe and Oliver Layton