Kevin Bennett


Spring 2010

Lab Assignment 4

In this assignment, I created a four-paneled Warhol-style image of myself in front of a blue screen, changed the background color from blue to green, and changed the background from blue to a mountain setting.

For the first task, I first defined the different effects I wanted to apply to the original blue screen image, then cloned the original image four times, applied the different effects, and finally, put them all together using a defined "putPixmap" function which takes a destination image (from the command line), a source image (from the command line), and an x and y value of where the upper left-hand corner of each source gets placed in the destination. The function then saves the new image as warhol.ppm. The effects that I used were: swapping the red and green values, halving the red value and setting the green value equal to that (effectively removing red and green, and leaving the blue), setting each pixel to its "opposite" color value, and washing the whole picture in red. Here is the image I ended up with:

For the second task, I used an "if" statement to "select," in a way, the very blue pixels and change them to green (30, 100, 30). Here is the picture I ended up with:

Finally, as an extension, I placed myself in front of a background (mountains). For this, I used similar code as the last function, except I added the variables r1, g1, and b1, and set them equal to the color values of a pixel from the mountain image in the "for" loops. Then, instead of setting the very blue pixels equal to 30, 100, and 30, I set them to r1, g1, and b1 and used and "else" to set the correct pixels to the correct colors from the source blue screen image.

bkgd = graphics.Pixmap( argv[1] )
    pmap1 = graphics.Pixmap( argv[2] )
    for i in range( pmap1.getHeight() ):
        for j in range( pmap1.getWidth() ):
            ( r, g, b ) = pmap1.getPixel( j, i )
            ( r1, g1, b1 ) = bkgd.getPixel( j, i )
            if b >= 2.0*r and b > g:
                pmap1.setPixel( j, i, ( r1, g1, b1 ) )
                pmap1.setPixel( j, i, ( r, g, b ) ) 'mountains2.ppm' )
Here is the image I ended up with:

And there I am, in all of my jacketed glory, in front of the Rocky Mountains.

In the final function, I decided not to use the putPixmap function because it kept giving me problems, so I just used the code I mentioned above and then saved the variable that I had set my source image to as the new pixmap file rather than the background.

Overall, with a few minor hiccups, this task went pretty smoothly. At least, better than last time.