## CS 1110/1111 - Spring 2015 - Homework Assignments

Important Links: Submit POTDs to the Automated Grading System and Join the TA Office Hour Queue

### Program of the Day

#### POTD 20 - BlurImage.java - Due: Friday, April 24, 11:00 AM

We would like to finish a library that will take a Picture and display a blurred version of that image, based upon a particular radius. We have written part of this class for you. You need to add two methods to this class to make it work properly.

To get started, download this project and import it into Eclipse: ImageManipulation.zip

If the project doesn’t work for you, here’s a jar file that you can add to your build path (ask a TA for assistance) along with some pictures to work with:

This project has the Picture class preloaded in it, along with some very basic sample code with three images you can play with.

##### The Algorithm

One way to blur an image is to take each Pixel from the original picture and then replace that picture with a Pixel of the average color of all the Pixels around it in a certain radius. For example, if you want to find the blurred value of Pixel at position (10,12) with radius 4, you would find the average of the red, blue, and green values of all of the Pixels found in the area between (6,8) and (14,16).

##### getSubImage

Write a method with the following header:

public static Picture getSubImage(Picture s, int sx, int sy, int w, int h)

where s is the source Picture, sx and sy is the upper-left corner of the sub image, and w and h are the width and height of the sub image.

Your method needs to handle boundary checking. If the desired sub image would try to pull an image that falls outside the boundaries of the source image, you should shift the sub image back onto the image, keeping the width and height of the sub image the same.

For example, assume the source image is 400x300.

• If the sub image’s upper-left corner is (400,300) and the sub image should be 100x100, you should adjust sx and sy to be (300,200)
• If the sub image’s upper-left corner has negative values, those values should be set to 0.
##### getAverageColor

Write a method with the following header:

public static Color getAverageColor(Picture p)

where p is the Picture that should have its Pixel values averaged.

This method should add up the red, green, and blue values of each Pixel and divide by the total number of Pixels in the source image. Create a new instance of the Color class with these averaged values.

##### blur

Here is the blur method you should use. Note that it uses the two methods above in its implementation:

##### Example

The blurred image with radius 4 should look like this:

blur4.jpg

The blurred image with radius 10 should look like this:

blur10.jpg

If you would like to do a pixel by pixel comparison with your resulting image with ours, please use these reference images. You can write code to load in these images and compare with your own results!

Submission: Please submit BlurImage.java to the grading system.