Project 4: The Warhol Project
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.
Make sure you have copies of the graphics.py and display.py files.
You can grab your picture from the photo directory.
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.
In your filter.py file, create a function putPixmap which
takes four arguments. The first argument will be a destination
Pixmap, the second argument will be a source Pixmap, and the last two
arguments will be an x, y location to place the second Pixmap into the
first. The function outline in comments is given below.
For each comment inside the function below, you need to write one line of python code.
# place src into dst with upper left at x, y in dst def putPixmap( dst, src, x, y ): # loop over each row i in src # loop over each column j in src # from src, get the (r, g, b) value at pixel (j, i) # in dst, set location (x + j, y + i) to (r, g, b) # return
Once you have written your function, 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:
python testPutPixmap.py miller.ppm
Remember that the Zelle graphics package can read only PPM type images.
- Create three more functions like swapRedBlue that edit the colors in a Pixmap to achieve some effect. See if you can emulate some of the Instagram effects.
Your main warhol program should read in one image, create four copies
of it, use your manipulation functions to change their colors, create
a new blank image that is width*2 by height*2 and then use the
putPixmap function to insert the four edited images. Finally, it
should write out the collage image.
def main(argv): # if the length of argv is less than 2 # print a usage statement # exit # read in the Pixmap from argv, put the result into a variable (e.g. pmap) # clone pmap and assign it to a new variable (e.g. map1) # call your first manipulator function on the clone # clone pmap and assign it to a new variable (e.g. map2) # call your second manipulator function on the clone # clone pmap and assign it to a new variable (e.g. map3) # call your third manipulator function on the clone # clone pmap and assign it to a new variable (e.g. map4) # call your fourth manipulator function on the clone # create a new Pixmap that is 2*width x 2*height and store it in a new variable # put map1 into the collage at (x, y) = (0, 0) # put map2 into the collage at (0, height) # put map3 into the collage at (width, 0) # put map4 into the collage at (width, height) # save the map to a file # return
Finish up this task by putting a call to main inside the conditional statement we've used before. Then call your python program and view the collage.
Your last task is to create a python program that reads in your
blue-screen image and turns the blue-screen pixels to a different
color. The rest of the pixels should remain untouched. You will need
to loop over each pixel in the image and test if it is very blue. If
it is very blue, change its color. Otherwise, leave it alone.
A reasonable test for 'very blue' is if the blue channel is at least twice the red channel and also bigger than the green channel.
- Create more effects and a bigger Warhol style collage.
- Do something more interesting than a single color to replace the blue screen.
- Place yourself in a scene. Start with a background scene that is the same size image as your blue-screen image.
- Enable your Warhol program to read in multiple images from the command line and make a collage for each one, or a collage that integrates several images.
- Make a function or functions that modify the image based on one or more parameters and demonstrate that you can make several different output images by varying the parameter.
Make a new wiki page for your assignment. Put the label cs151f12project4 on the page. Each of you needs to make your own writeup.
In addition to making the wiki page writeup, put the python files you wrote on the Academics server in your handin directory.
In general, your writeup should follow the outline below.
- A brief summary of the task, in your own words. This should be no more than a few sentences. Give the reader context and identify the key purpose of the assignment.
- A description of your solution to the tasks, including any images you created. This should be a description of the form and functionality of your final code. You may want to incorporate code snippets in your description to point out relevant features. Note any unique computational solutions you developed.
- A description of any extensions you undertook, including images demonstrating those extensions. If you added any modules, functions, or other design components, note their structure and the algorithms you used.
- A brief description (1-3 sentences) of what you learned.
- Don't forget to label your writeup so that it appears in the listing on the main wiki page for the course. For this lab, use cs151f12project4