[an error occurred while processing this directive]

Partner Work 2 - Image Filters

[an error occurred while processing this directive]

Background

Today we exercise our newly learned skills about methods, method parameters, objects, and Java's "wacked out" math to build a Processing program that filters images in eight different ways. Images are just rectangular regions of pixels. We learned previously that pixels are just dots of a uniform color.

A key concept in this program is the Color object. Recall that colors are defined by three integers between 0 and 255: a red value, a green value, and a blue value. So if we wanted to create a new Color object named pxColor that started off being pink, our code might look like this.

Color pxColor = new Color(255, 223, 223);

Suppose that during the running of your program, the color represented by the pxColor object changed, or in other words, its red, green, and blue values became different numbers. To get the current values of red, green, and blue, then we would write code like this.

int r = pxColor.getRed();
int g = pxColor.getGreen();
int b = pxColor.getBlue();

As mentioned in the opening paragraph, we are going to create eight different image filters. Each filter is going to be created in a different Java file, and each file is going to start with code that looks similar to what is shown below.

public Color computeColor(Color startColor) {
  return null;
}

Your job today is to write the code necessary to compute a new color and return it. There are three basic tasks for each computation:

  1. Create variables and use Java's math capabilities to compute three new values for red, green, and blue based on the old red, green, and blue values in startColor.
  2. Create a new color object that will store the new values computed in step 1.
  3. Delete the return null line and replace it with a line that returns the new color object created in step 2.

Specific Directions

Setup

  1. Start by importing pw2ImgFilt.zip into Eclipse.
  2. Notice that inside the src folder there are three subfolders:
    • data (pictures live here)
    • photomanipulation (Java/Processing code lives here)
    • yourwork (this is where you will do your work)
  3. Open the photomanipulation folder and double-click the PhotoManipulation.java file.
  4. Run the program as an Applet.
  5. Try clicking the buttons... the only one that works is New Pic. Once you're done with your work though, it will look like this:

Your browser is not capable of showing Flash movie files. Unfortunately, you will not be able to access this movie.

Your Work

You will modify each of the files listed in the yourwork folder.

  1. ColorSwap.java: Rotate the values of the starting color so that the old red is the new green, the old green is the new blue, and the old blue is the new red.
  2. Darker.java: Make each red, green, and blue value 70% of its starting value.
  3. Grayscale.java: Compute the average of the starting color's red, green, and blue values. The new color uses this average for each of its red, green, and blue values.
  4. Lighter.java: For each starting color value, compute the maximum amount that the value could be increased (recall that a color value cannot exceed 255). Then compute 30% of this maximum and add it to the original value to get the new value.
  5. Negative.java: Invert each starting color value on the 0-255 scale. For example, a starting color of (0, 255, 127) should become a new color of (255, 0, 128). Another example: (50, 150, 250) becomes (205, 105, 5).
  6. Posterize.java: Create a range variable as follows:
    int range = 255 / 6;
    To get the new color, divide each starting value by the range, then multiply that result by the range. What effect does this calculation have on the image? Play with the range denominator to see what happens.
  7. RedFilter.java: The new color should use the starting red value, but should set green and blue to 0.
  8. Static.java: This is optional and will not be graded. Create "static" by ignoring the starting color value and creating random values for red, green, and blue. Hint, the following line of code creates a random number between 0 and 1.
    double d = Math.random();
  9. TieDye.java: Well, it's not really Tie Dye, but it is fun. The new values are the last two digits of the old values. For example, (2, 20, 200) becomes (2, 20, 0) and (44, 188, 210) becomes (44, 88, 10).

More Fun

Want to use your own images? Drag a picture from your computer's folder onto the data folder in Eclipse (use the default Copy option). Then go find these two lines:

  pics.add(loadImage("lily.jpg"));
  pics.add(loadImage("wynn.jpg"));

Add an identical line with the name of your file. For example, if your file was called elonfun.jpg, then your code should now look like this:

  pics.add(loadImage("lily.jpg"));
  pics.add(loadImage("wynn.jpg"));
  pics.add(loadImage("elonfun.jpg"));

Resources

Do not use any resources other than the ones listed below. In particular, do not search the Web for code samples. The point of these exercises is to create code on your own, not to find an answer that has already been created.

Grading

Recall that partner work assignments are worth 30 points each. Refer to the syllabus for more course grading information. Each of the 8 problems are graded as follows.

Note: Mathematically inclined people just noticed that 32 points are possible. You will not be able to exceed 30 points on this assignment, even if you score more.

Submission

Submission directions are different than the previous assignment. Read carefully.

Each pair will submit 1 file by taking two actions: creating a printout and providing an electronic submission. Details are below.

  1. Ensure that each pair member's name appears as a comment at the top of each of the eight graded code files. Replace the comment that is already there
  2. Export your code to a zip file and upload the zip to Moodle. Directions for exporting can be found in Eclipse Basics.
  3. Copy and paste all code from the "yourwork" set of files into a single email message to the instructor, cc'ing your partner on the message. Put the code in the body of the email; don't use attachments.
  4. Each pair will submit only 1 file. Only one person of the pair should submit to Moodle. Only 1 person should provide email. Do ensure however that each member of the pair has a copy of the submission.
[an error occurred while processing this directive]