This assignment is to be done individually without your teammate. You can talk to other people in the class (including your teammate), me (Dave), the prefect, and lab assistants for ideas and to gain assistance. You can help each other debug programs, if you wish. The code that you write should be your own, however, and you shouldn't hand a printout of your program to others. See the course syllabus for more details or just ask me if I can clarify.
Here are two more image functions to write (plus a main()).
scale(image, scaling)
Scales your image. If scaling
is 2, for example, each
side of your new image should be double the size of the
original. Likewise, if scaling
is 0.25, each side of your
new image should be 1/4 the size of the
original. If scaling
factor is less than or equal to 0,
do no image work at all and return None
. Otherwise,
return the new image.
Hint, of sorts: You've got a choice to make. Do you loop over all the pixels in the old image, and figure out where they belong in the new images? Or do you loop over all the pixels in the new image (which are initially unassigned), and for each one figure out which is the right pixel in the old image to copy in? One of these approaches is much easier than the other. Definitely spend time in advance thinking about what kinds of calculations you would have to do for each of these approaches, and ask for help if you need it. It would be a shame to lose a whole lot of time programming up the "hard" approach to abandon it later.
Question I've sometimes gotten from students in the past: What if the new image is bigger than the original? Do I need to interpolate between pixels to calculate appropriate pixel values and so on?
Answer: No. Every pixel on the new image should just be a copy of some pixel on the old. The challenge is in figuring out which one. If the new image is smaller than the old, then some of the pixels on the original will be ignored. If the new image is larger than the old, than some of the pixels from the original will be duplicated.
blur(image, radius)
Blurs an image. For each pixel, average all of the pixels within a square centered at that pixel and with a "radius" as given. In other words, if your radius is 3, your square should go 3 pixels left, 3 pixels right, 3 pixels up, and 3 pixels down from the center to form a 7 x 7 square. Make sure to put all of your results in a new image, instead of overwriting your original as you go; otherwise, your blurred pixels will cascade on top of each other. You'll want to work with a small image for this task, as blurring in Python can take some time. Here is a picture of me which is nice and small. Nonetheless, some approaches to programming this result in much slower algorithms than others. On my office machine, which I think is slightly slower than the lab machines, I can blur this small image in about 2 seconds with a radius of 3 and about 9 seconds with a radius of 10. Any technique that works will receive most of the points for this problem (assuming it runs in under one minute for a radius of 3, I can't keep the grader testing these indefinitely), but you need to end up with timing more-or-less close to my numbers if you wish to earn it all.
You can choose to ignore blurring around the edges of the image, that is in the range where the blurring square would run off the edge of the image. Alternatively, if you like, you can blur those pixels by using whatever pixels you do have in range.
main()
Test your program by an appropriate main() function, which you should also submit as part of your photolab.py.
Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 306 to help out if you need it.