Due: Tuesday, February 28, 2017, 11:59 pm

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.

Here is the reference guide to the graphics package.


Make sure you have copies of the graphics.py and display.py files.

For this assignment you're going to create two python programs. One will generate a Warhol style collage. The other will change the green screen or blue screen to a different color. Both will write their results to an image file, which you can then view with your show program.

  1. In your filter.py file, create a function placePixmap 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 placePixmap( 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)

    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 testPlacePixmap.py cupcakes.ppm

    If you look at the end of test program, you will see that it writes the output to a file called duplicate.ppm. You can use your show.py program to view the duplicate.ppm image. It should show two copies of the original image, side-by-side.

    As you are working with your code, remember that the Zelle graphics package can read only PPM type images.

    Once you are confident that your placePixmap function 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.

  2. 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. Note: when we say "like swapRedBlue", we do not mean "variants of swapRedBlue". 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).

    The first required picture is an image demonstrating your filters. You can include a separate image for each filter, or one collage-like image demoing all of them (you can take a screenshot). Note: If all of your filters are shown in your Warhol image (the next task), then it is OK to skip this image. If you skip this image, be sure and mention that you skipped it in your writeup.

  3. Your main warhol program (which you should put in a file named warhol.py) should read in one image, create four copies of it, use your filter functions to alter them, create a new blank image that is width*2 by height*2 and then use the placePixmap function to insert the four edited images. Finally, it should write out the collage image. The code below is a skeleton of the algorithm.
      def main(argv):
          # if the length of argv is less than 2
              # print a usage statement
              # exit
          # read in the Pixmap from argv[1], put the result into a variable (e.g. pmap)
          # clone pmap and assign it to a new variable (e.g. map1)
          # clone pmap and assign it to a new variable (e.g. map2)
          # clone pmap and assign it to a new variable (e.g. map3)
          # clone pmap and assign it to a new variable (e.g. map4)
          # call your first filter function on map1
          # call your second filter function on map2
          # call your third filter function on map3
          # call your fourth filter function on map4
          # 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 big map to a file

    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.

    Tip: For this function, helpful comments would indicate the different sections of code (e.g. "read in one pixmap", "make 4 copies of it", "make an empty pixmap big enough to hold 4 copies of this one", and "put the 4 filtered images into the big one"). And, of course, a docstring is a must.

    The second required picture is an image of your Warhol collage (you can take a screenshot of it).

  4. Your last task is to create a python program that reads in your green-screen or blue-screen image and turns the green-screen or 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. A reasonable test for "very green" is if the green channel is at least twice the red channel and also bigger than the blue channel.

    The third required picture is an image of your image with the changed background (you can take a screenshot of it). Note: If this filter is shown in your Warhol image (the previous task), then it is OK to skip this image. If you skip this image, be sure and mention that you skipped it in your writeup.


Write-up and Hand-in

Turn in your code by putting it into your private hand-in directory on the Courses server. All files should be organized in a folder titled "Project4" and you should include only those files necessary to run the program. We will grade all files turned in, so please do not turn in old, non-working, versions of files.

Make a new wiki page for your assignment. Put the label cs151s17project4 in the label field on the bottom of the page. But give the page a meaningful title (e.g. Ying's Project 4).

In general, your intended audience for your write-up is your peers not in the class. Your goal should be to be able to use it to explain to friends what you accomplished in this project and to give them a sense of how you did it. Follow the outline below.

To check whether you've made your summary clear, you may ask yourself the following questions:

© 2017 Ying Li. Page last modified: .