CS 117: Introduction to Computer Science

Image Processing

If you have ever used image-manipulating software (e.g. Adobe Photoshop), you know that you can do lots of crazy things to digitized images. Some of the games you can play involve very complex mathematics, but others are pretty easy. For example, turning a color image into a black-and-white image is easy: for each pixel, take the average of the pixel's red, green, and blue values, and use that average as the new red, green, and blue values for the pixel.

There is a nice image-manipulation library for Python known as the Python Imaging Library, or PIL. You will use PIL to implement a few wacky image transformations.

More specifically, for this assignment, you will implement the methods whose interfaces are specified in ximage.py. Do not change the interfaces in any way. When you hand in your program, please include the original testing code, found at the bottom of ximage.py.

More details

The XImage class has several utility methods already written for you: __init__, save, revert, and show. It also includes an implementation of the toGreen method. Suppose, for example, you were using this picture of my children harrassing Babe the Blue Ox in Bemidji, Minnesota a few years ago:

If you executed the code:


    image = XImage('babe.jpg')
    image.toGreen()
    image.show()

you would end up with this:

Your job is to implement the methods toGray, reflect, tile, and addFakeScratches to yield images like these:

Finally, if you do the following:


    image = XImage('babe.jpg')
    image.addFakeScratches()
    image.medianFilter()
    image.show()

you should get something like this:

Some notes

Have fun, and...

...start soon--some of these are tricky.