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.
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.
For each comment inside the function below, you need to write one line of python code.
# place source into destination upper left at x, y in destination def putPixmap( destination, source, x, y ): # loop over each row, i, in source # loop over each column, j, in source # from source, get the (r, g, b) value at pixel (j, i) # in destination, 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 testPutPixmap.py miller.ppm
Remember that the Zelle graphics package can read only PPM type images.
Once you are confident about the code, remove the comments that we supplied. Because they simply describe each line of code, they don't help the reader understand the overall purpose of the code. Helpful comments include the docstring (which you need to write), which explains the meaning of each parameter. If you find them helpful because they remind you how to code up our instructions, then you may leave them there. But don't assume your code is well-commented because you copied our comments.
def main(commandLineStrings): # if the length of commandLineStrings is less than 2 # print a usage statement # exit # read in the Pixmap from commandLineStrings[1], put the result into a variable (e.g. pixmap) # clone pixmap and assign it to a new variable (e.g. map1) # clone pixmap and assign it to a new variable (e.g. map2) # clone pixmap and assign it to a new variable (e.g. map3) # clone pixmap and assign it to a new variable (e.g. map4) # call your first manipulator function on map1 # call your second manipulator function on map2 # call your third manipulator function on map3 # call your fourth manipulator 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.
Important: You'll want to add the pictures to your writeup, but the wiki doesn't support the .ppm format. There are two ways to get around this problem. The first is to take a screenshot like we've done in the past and upload that instead.
Alternatively, you can use some cool image-manipulation software installed on the lab machines. (Sadly, it isn't automatically built into Mac OS X the same way python is.) To do this, use convert at the command line like so:
$ convert myImage.ppm myImage.png
You can even resize it this way:
$ convert myImage.ppm -scale 25% mySmallerImage.png
More information about convert is available at the ImageMagick web site.
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.
Before handing in your code, double check that it is well-styled:
Make a new wiki page for your assignment. Put the label cs151s14project4 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 private handin directory.
In general, your writeup should follow the outline below.