Image Processing 1

Table of Contents

This is a pair programming assignment. If you are working in a pair, this means that you and your partner should be doing the entirety of this assignment side-by-side, on a single computer, where one person is "driving" and the other is "navigating." Set a timer to swap every 15 minutes. You can choose your favorite from this online timer page. Make sure your sound volume is audible, but not so loud to disturb the people around you.

If you are working in a pair, only one of you needs to submit your work via Moodle. That said, you should both have a copy of your work in case you want it someday, so make sure that both of you have copies of it; you can email it or use some other mechanism to transfer it.

We will use anonymous grading on Moodle, which means that the grader won't see your name until after the grading is done. This is an easy way to help add an extra element of fairness to the grading. Therefore, make sure your name doesn't appear on your actual submission. When you submit via Moodle, it will know you are. Thanks!

1 Overview

This is your chance to practice some basics of image processing. This is a warmup to the next assignment, where you'll do some "green screen"-like special effects.

2 Getting Started

Create a directory called image1 for this assignment. To facilitate reading in, storing, and manipulating image files in "standard" formats (like .jpg, .gif, and .png), we will use a module called images.py. Copy images.py into your directory from the above link or from the course website. Here is the documentation for images.py.

If you're working on your own computer and not using the department virtual machine or x2go, you'll also need to install Pillow (aka the Python Imaging Library (PIL)), which images.py uses. (Again, to be clear, Pillow is already installed in the labs, on the department virtual machine, and on x2go.) If you're using the Windows Subsystem for Linux (WSL) under Windows 10 on your own computer, you'll need to execute the following from a Windows bash prompt:

$ sudo apt update
$ sudo apt install python3-pil.imagetk

You'll also need some images to work with. You can use pretty much any photos that you've taken yourselves. If you download photos, make sure that they are appropriately licensed for your use (e.g., via Creative Commons, but make sure to check with CC license is being used.). Or, feel free to download this photo of Budapest I took while I was there.

3 Applying basic filters to an image

We'll start out with some basic image manipulations first. Your task is to write a Python module called photolab.py. It should contain the following functions:

3.1 onlyRed(image)

Creates and returns a new image containing only the red aspects of the original image. You can do this by setting all the green and blue values to 0.

3.2 negate(image)

Creates and returns a new image that is a conversion of the original image to "negative" form (like a photographic negative). Here, you don't necessarily have to duplicate precisely the same technical visual effects that a photonegative actually uses. But you should modify all colors in a way that turns black into white, white into black, dark colors into light, light into dark, etc.

3.3 main()

Write a main() function that tests the above functions by using an image file and making red and negative versions of it appear on the screen. When we test your code, we will remove your main() and add our own. If you have carefully followed the above specifications, it should work perfectly! As an example, we should be able to write code in our main() like:

imageOriginal = FileImage('budapest111.jpg')
redImage = onlyRed(imageOriginal)
redImage.show('Only red',0,300)

4 Test your code

As in the last assignment, you should test your code. Do some more examples on your own, work out by hand what the results should be, and see if your program gets them right. We will test your program similarly.

Make sure to also to think through all the possible ways in which your program might go wrong, and test them.

5 Design and Style

Make sure that your program follows good design and style. See the guidelines from recent assignments. If you really want to learn lots about Python style, the official style guide for Python is a great read.

6 The last point

If you complete the above successfully (and have good style in your code), you will receive nearly all the points for the assignment. If you get this far, you should feel proud of your achievements! If you want to push yourself harder and go for the last point, do the following extra challenge.

This underwater image has some fish within it, but they're really hard to see. Write an additional function called fixUnderwater(image) that returns a new image where the fish are easier to see. We will only test this function by using it on the provided image.

7 Submit your work

When finished, zip up your code and submit your work through Moodle.

Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 102 and CMC 306 to help out if you need it, and you can attend prefect sessions as well.

Author: Dave Musicant

Emacs 24.5.1 (Org mode 8.2.10)

Validate