The purpose of this project is to make a collection of images in the style of Andy Warhol. You'll do this by manipulating the pixel colors of an image.
Here is the reference guide to the graphics package.
For this assignment you're going to create two python programs. One will generate a Warhol style collage. The other will change the blue screen to a different color. Both will write their results to an image file, which you can then view with your show program.
As you are working with your code, remember that the Zelle graphics package can read only PPM type images.
placeImagefunction, then add it to your filter.py file.
def placeImage(dst, src, x, y): '''Place src into dst with upper left at x, y in dst Parameters: dst: destination image src: source image (x,y): location to place the second Image into the first ''' # loop over each row i in src for i in range(src.getHeight()): # loop over each column j in src for j in range(src.getWidth()): # assign to the tuple (r, g, b) the result of calling # getPixel on src with arguments (j, i) (r, g, b) = src.getPixel(j, i) # Using dst, call the setPixel method to set location # (x + j, y + i) to the color (r, g, b) # # The color_rgb function expects ints between 0 and 255 # for each color channel. dst.setPixel(x + j, y + i, graphics.color_rgb(r, g, b))
placeImagetakes in four arguments:
setPixelfunction expects a Zelle color. You can create a Zelle color using the function
graphics.color_rgb(r, g, b). The
color_rgbfunction expects values between 0 and 255 for each color channel.
placeImagefunction, you can use this file to test it. Run the test program on the command line and give it an image filename as its argument. For example:
python3 testPlaceImage.py miller.ppm
If you look at the end of test program, you will see that it writes the output to a file called duplicate.ppm.
placeImagein your report:
dst? How about
placeImagefunction works, please remove the comments that we supplied. They don't help the reader understand the overall purpose of the code because they are a line-by-line annotation of what each line does. In most cases, that is obvious from the code itself. Helpful comments include the docstring (which you need to write), which explains the meaning of each parameter.
Add code to filter.py: Create three more functions like
swapRedBlue that edit the colors in a Image to achieve some effect. See if you can emulate some of the Instagram effects. Note: when we say "like
swapRedBlue", we do not mean "variants of
Note: A filter that simply reorders the color channels will not count towards your three (though you are welcome to write them in addition to your three, if you like the effect).
Hint: You will likely make use of set and get methods for
Image objects. Review the code from lab and
Make your main warhol program that you should put in a file named warhol.py. Code that implements the following algorithm should be placed within a function called
mainfunction take a parameter called
argv. This will represent the user-specified input arguments from the command line with the filename string of the image that we want to load in for our Warhol 2x2 collage.
sys.argvonly in your top-level code (inside
if __name__ == "__main__":). If you have another function that accesses the command line arguments via
sys.argv, then you are dramatically restricting the breadth of programs that can import and use that function.
Imageobject to a variable (e.g.
Imageobject four times, then apply one of Instagram-style filters on each.
Imageobject that has twice the width and height of the image that you loaded in. This will be your Warhol collage.
placeImagefunction to arrange your four filtered images on the larger blank
Imagethat you just created on a 2x2 non-overlapping grid. For example, the first filtered image should start at (x, y) = (0, 0). The first filtered image should be placed to its right should be placed at (x, y) = (width, 0), etc.
Finish up this task by putting a call to
main inside the conditional statement:
if __name__ == "__main__": # Call to main here, with command line arguments passed in
mainis a must!
In your writeup, include a picture of your Warhol-style image. This is required picture 1.
Your last task is to create a python program that reads in your blue or green-screen image (your choice) and turns the background pixels to a different color. Call it greenscreen.py or bluescreen.py, depending on the background color of you image (the images will be placed in Courses/CS151/CourseMaterials). The rest of the pixels should remain untouched.
You will need to use a nested loop to test if every pixel in the image is very blue/very green. If it is very blue/very green, change its color. Otherwise, leave it alone. A reasonable test for 'very blue' is if the blue channel is 1.5 times the red channel and also bigger than the green channel. You can do something similar to define 'very green'.
In your writeup, include a picture demonstrating your altered background. This is required picture 2.
Congratulations on completing the core tasks! Between the code (and comments) that you’ve already written and the report (below), 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! If you’re exhausted or running out of time, this is a perfectly respectable place to stop. If you’re up for it, you have the option to design your own extension or pick one of the following examples. To earn all 4 extension points, concentrate on one design challenge, and really dig into it both computationally and creatively. What will you create?
Here are some example extensions:
Remember: We award extension points based on the depth of your computational exploration. A good extension should interest you and show us that you can apply this week's material in creative ways.
cs151s19project4on the report page.
Remember, the written report counts for 5/30 points that you earn for the project.
In general, your report should follow the outline below.