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.
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:
Because this assignment has several pieces, some of which are quite a bit more difficult than others, I will instruct the grader to treat the tile and medianFilter methods as determining the difference between an A program and a C program. More specifically, a good job on toGray, reflect, and addFakeScratches will be passing work.
Though you probably don't need any more of the PIL library than I have already included in the sample code, you may wish to consult the PIL documentation.
Installing PIL to Windows is quite easy, so if you are using IDLE on Windows, you shouldn't have much trouble. I haven't tried installing PIL on a Mac, however. It may be pre-installed, but you'll need to experiment. In any case, PIL is installed on the machines in the CS lab, so you can do your work there if need be.
...start soon--some of these are tricky.