Computer Science 110
Foundations of Computing through Digital Media

Denison

CS 110 Lab Project 7

More Pictures

Due: By 5 p.m. Friday, October 19th

In this lab, we will continuen with some more Picture/jpeg manipulations. Once you have these completed, you are encouraged, for extra credit, to program some additional (non-trivial) transformation, and/or to create a user interface that allows a user to perform a sequence of any of the transformations we have programmed so far. ... kind of your own PhotoShop.

Problem: Picture Manipulations

In the Picture manipulations we have attempted so far, we have either performed our transformation "in place," in which the modified pixels are simply a part of the original Picture object, or, in the case of the pixel averaging for the dithering application, there was a one-to-one correspondence between the original source picture and the destination picture. That is to say, the x and y values in the coordinate system were identical between the original and the picture transformation. In this problem, we will no longer have that one-to-one correspondence of x and y coordinate values between the original and the transformation. But like in the dithering example, we will have separate pictures for the original and for the transformed picture, giving us both a source picture and a destination picture. Based on the transformation, we will have to determine a size for the destination picture and create a new blank picture using the makeEmptyPicture() function.We will again use JES for developing these programs.

In this part, you will be writing four programs.  The first will flip an image horizontally.  The second will create a scaled version of an image.  The third will create a four-fold tiling of an image. And the last will create a composite of the image and its reflection.  For example, if your initial image was the octopus picture from the last lab:

then the transformed pictures will look something like this:


For each of the following problems, the main() function will perform a pickAFile() and then main() will create and show the Picture object. The main() function will then call a subordinate function that takes a picture object as a parameter and performs the transformation described below, finishing with a call to show(). The subordinate function should be responsible for creating the new destination picture, and for returning that picture at the end of the function. After completion of the transformation, the main program should ask the user if they wish to save the file and, if so, save a copy of the transformed picture to a location of the user's choice.

When you turn in your assignment, I would like a jpeg of your favorite results for each of the transformations.

Flip.py

Write a program that flips the selected image. In the flipped image, the top row becomes the bottom row, the second row becomes the second to last row, etc. In solving the problem, think in terms of sequences. You will have the "normal" sequences of x and y, but you can consider these to be the x and y values for the destination picture. Then think about a different sequence of src_y values. What is the sequence? Using the techniques we have developed, how do we make the sequence start at the right value and incrementally maintain the correct value?

Scale.py

Write a program that creates a scaled version of the original source image. The program should start by asking the user if they want to scale up, or to scale down. Look for appropriate interfaces in JES to get such a response. Then the program should ask the user for an integer scale factor, k. If scaling up, the new image should be k times as large in both width and height. If scaling down, the new image should be 1/kth the size in both width and height.

Tile4.py

Write a program to tile an image four times within a single new destination Picture. The resultant picture should have the same width and height as the original, and the sub image is like the above scale problem with a scale down factor of 2.

Reflect.py

Write a program to create a new image where each pixel is the average of its original and the corresponding pixel in its reflection about a vertical center line. The y values of the original pixel and the corresponding pixel are the same, while an original x of 0 is paired with an x of width-1; an orginal x - 1 is paired with an x of width-2, etc.