Computer Science 171
Introduction to Computer Science

Denison
CS171 Homework 6


Homework 6

Picture Project Part I

The purpose of this assignment is to give you practice at both of the following:

Assignment

The basic assignment is to create a digitial picture collage. An application program will do this by manipulating a minimum of 4 input digital pictures, and will perform manipulations on these pictures by scaling them, cropping them, converting them to greyscale, posterizing them, and then composing them onto a newly created destination canvas. Finally, the application program will write the result to a new jpeg file.

Note that the application program is the orchestrator and performs all interaction with the user. The object methods that we describe below will manipulate the current MyPicture object and, for most, will return a new MyPicture object. The one exception to this is the object method for placing a given picture passed as a parameter on top of the current picture (the overlay method). This object method will operate on the current object and will not return a new MyPicutre object.

Operations

Cropping: Cropping is the act of removing from the current MyPicture image a portion of the image. You need to specify the (x,y) of the upper/left coordinates of the rectangular region to extract along with the width and height of the rectangular region to extract. Return a new MyPicture image of the appropriate dimensions that contains only the cropped region. Name your routine crop. Gracefully handle the case where the cropped region extends beyond the borders of the original image.

public MyPicture crop (int xStart, int yStart, int width, int height)

Scaling: Scaling is the process of changing the size of an image. For partial credit, provide a method to halve the width and height of the given picture. For complete credit, provide a scaling factor as a double and use this to determine the size of the new image. Multiply the dimensions by this factor to increase/decrease the height and width of the object. Expand or contract the pixels to create a new copy of the original image.

public MyPicture halveImage()

public MyPicture scale (double scaleFactor)

Greyscale: Generate a greyscale version of the current MyPicture object and return this new MyPicture as a result. Recall from class that we obtain the greyscale intensity by averaging the red, green, and blue intensities for a given pixel in the source (current image) and using this greyscale intensity as the value for all three of the red, green, and blue intensities in the newly created image.

public MyPicture greyscale ()

Posterize: Posterization reduces the number of colors in a picture. We do this by defining intensity ranges for each of red, green, and blue, and colors within those ranges all get mapped to a single color. Following is one such mapping:

public MyPicture posterize()

You could also imagine defining arguments that allow the caller to specify the thresholds and/or the color values. You are welcome to generalize your posterize method in this way.

Overlay: Place one image over top of another. You should provide the (x,y) coordinates to specify the upper/left corner of the overlay position. If the overlain image extends beyond the boundaries of the underlying image, then ignore that portion of the overlain image and copy as much as is possible. This is the one method that will operate "in place" on the current image, which serves as the background. So the method will return a void. The second image is passed as a parameter.

public void overlay (int xOrigin, int yOrigin, MyPicture topPicture)

Programs will be turned in by copying the Java source file to the Assignment Inbox area of the Shared Workspaces under the Instructor/Class-Section for this course. Please create a folder named Program2 and place your source files within that folder.