
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 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!
Write the 3 additional filter functions in your filter.py file. Each function should be structured similarly to swapRedBlue taking in one parameter, which is an Image object that you will be modifying.
def filterName(img): '''Filters every pixel in `img`'''
In your report section called Art Reflection discuss which Andy Warhol composition inspired you and what aspects of the compositions you emulated.
Update your main code in filters.py to only handle command line arguments and call your test function.
Modify your test function to have 2 parameters, the image filename and string which represents the chosen filter. Modify the functions code so that the new parameter controls which filter is applied to the image.
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.
Here is an example of showing the image miller.ppm after it has been processed with the swapBlueRed filter. The resulting image should also be saved in your project folder as a PPM file.
python3 filters.py miller.ppm swapBlueRed
You could use none or original to indicate leaving the image alone / not applying any filter.
filters.pyImagine giving filters.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 filters.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 filter.py <filename of image> <filter>
Call the exit function right after printing out the message to stop the program cleanly without crashing.
Test running filters.py with the correct and incorrect number of command-line arguments. For example, running filters.py:
Take a screenshot of each of the 3 filters applied separately to one image of your choice. Collectively, these are Required Image 1, 2 and 3 in your project. In the caption for each image, include the command line arguments that generate the image and a description of how the filter works.
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.
filters.py, the copyPixels function and imageList described below, to create a Warhol image on the `destinationImage`.Write a copyPixels function. This function should copy the pixels from one image (originImage) to a different image (destinationImage). The topleft_x and topleft_y parameters specify where on the destinationImage the originImage pixels should be copied.
def copyPixels(originImage, destinationImage, topleft_x, topleft_y): '''Copy pixels from the the image `originImage` to the larger image `destinationImage`. The image `originImage` should be positioned so that its top-left corner appears at (row , col) = (topleft_row, topleft_col) in the large image `destinationImage`. NOTE: (0, 0) is the top-left corner. Parameters: ----------- destinationImage: Image. Larger image to copy the pixels of image `originImage` to. originImage: Image. Image that has the pixels which will be copied to the destinationImage. topleft_x: int. x pixel position (column) in the image `destinationImage` where the top-left pixel of `originImage` should go topleft_y: int. y pixel position (row) in the image `destinationImage` where the top-left pixel of `originImage` should go ''' pass
Use a list of lists to store information about each image to be copied into in the image `destinationImage`. Each sublist relates to one of the four images and has four items:
destinationImagedestinationImageHere 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', filename], [img.getWidth(), 0, 'swapBlueRed', filename]]
In each sublist, the first two x and y values are positions of the top-left corner of each image in the image destinationImage. 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 filename of the image to be filtered.
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 4 in your project.
Create a new file called greenscreen.py.
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 (click on link to download image). You can think of the background replacement process as applying a special kind of filter to your green screen image:
Make a greenscreen function in greenscreen.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. The function returns the updated `greenImg` object. '''
where otherImg is the "exotic beach image" object. The function should implement the logic outlined in the above bullet points and docstring.
Recall that each pixel in a color image has three values (r, g, b). Each pixel is addressed by its row ("y") and column ("x"). The height of the image tells us the number of rows and the width of the image tells us the number of columns.
The Graphics module contains two functions that make it easy to get and set pixel values if you have an Image object. The three lines below demo how you would:
Image from a file (which you did above)img = graphics.Image((0,0), 'myImage.ppm') (r, g, b) = img.getPixel(42, 35) img.setPixel(42, 35,(2*r, 2*g, 2*b))
In your main function, create your two images objects, call greenScreen and display the blended image.
Save a PPM image of your green screen image in your project folder.
Take a screenshot; this is Required Image 5 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: Display in a new window the warhol image. Check if the required PPM images in your project folder, it should save a new PPM of your 2x2 Warhol image.python3 greenscreen.py: Display in a new window yourself on the beach. Check if the required PPM images are your project folder, it should save a new PPM of your blended images.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!
Document your AI usage in the format described here under "AI Usage Statement" OR if you didn't use AI answer the following question. The question should be answered in a short paragraph (100-250 words total) without using AI and take approximately 10-20 minutes to complete, including researching and writing.
Alternative Assignment: Find a specific example of Algorithmic Fraud Prevention and a company that provides the service. Research and explain an underlying component of the technology, computational method or machine learning model used, be as specific as possible. Describe a potential issue with using algorithmic fraud prevention, and how your specific example does or does not address it. Include at least one cited credible source (academic paper, official tech documentation, or reputable technical news outlet).
Congratulations on completing the core tasks! Between the code that you’ve already written and the report that you write, you’ve already earned up to 26/30 points for this project. If you turn it in by the first deadline that's 27/30 points.
The remaining 3/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; 27/30 is an A- 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 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:
warhol.py and greenscreen.py. This could include the filenames, and/or the filter names for each image. Make sure to include a usage statement, and explain how to run your code in your report. (.5-1pt per file)
To turn in your project, make sure you do all of the following:
hewolfe_Project6.zip.This section will help you convert images to PPM files so you can apply filters to images of your own. (optional)
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 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