CompSci 6
Fall 2008
Program Design and Analysis

Transforming Images

Images are stored by computers in a variety of formats, such as gif, jpg, tiff, and png. These formats differ in how faithfully they represent the original picture, how well they can be compressed to reduce the space each image takes up, or how well they can be copied from one type of computer to another. However, no matter what format the image is stored in, it can always be represented of as a mapping of (x, y) pixel position to a color (the range of colors may be restricted to values of grey or just black and white). Thus, for the remainder of this project, we will refer to all formats of digital images as pixmaps.

This programming project involves manipulating pixmaps by transforming each color in the original pixmap using the same algorithm. Your program will be able to read in gif, jpg, and png image formats, and perform several operations on these images including darkening, inverting, posterizing, coverting it to grey scale.

Today's classwork focuses on running a whole Java program that experiments with transforming images. You will write several methods to manipulate an image by directly changing the color of each pixel in the same way. As with the remaining projects in the course, you will use Eclipse to download a partial program called imageTransform from the assignment category to get started. To help get you started, you should read the following resources:

Specifications

For each of the problems below, you will complete the transformColor method of the appropriate class that, given a Color parameter representing a current pixel in the pixmap, returns a new Color whose component values have been changed based on the algorithm described that will replace the original pixel. To test your solution, right-click on the file named Main.java within your project and select Run -> Java Application from the menu that appears. This will cause a Java program to appear that allows you to open, transform, and save images. To load a different image to test, click on the Open button and select an image from the images folder there. To test your method on every pixel in the displayed image, click on the button corresponding to the name of the class in which you worked.

Negative
Create a photographic negative of the image by inverting each of the three RGB components of the current color. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (0, 255, 127) for its red, green, and blue components. In other words, each value is the other's opposite within the range of possible values from 0 .. 255. Thus, if this operation is performed on an image twice in succession, the image would appear unchanged.
Darken
Darken the image by reducing the values of each of the three RGB components of the current color by some amount (like the darker method of Java's Color class). Do not call the method, instead you will try to reproduce its effects by manipulating the three RGB components of the current color directly. Note, this method should exactly undo the results of performing the Brighten action (as long as any of the image's colors are not already as bright as possible), so that doing one operation then the other should result in no net change in the image. Be careful not to produce a color value outside the range of possible values from 0 .. 255.
Brighten
Brighten the image by increasing the values of each of the three RGB components of the current color by some amount (like the brighter method of Java's Color class). Do not call the method, instead you will try to reproduce its effects by manipulating the three RGB components of the current color directly. Note, this method should exactly undo the results of performing the Darken action (as long as any of the image's colors are not already as dark as possible), so that doing one operation then the other should result in no net change in the image. Be careful not to produce a color value outside the range of possible values from 0 .. 255.
Posterize
Create a posterized version of the image by reducing its total number of colors. To do this, you should restrict the values each of the three RGB components of the current color can be. Specifically, if the value of a component is between 0 and 63 inclusive, it should be set to 49; if the value of a component is between 64 and 127 inclusive, it should be set to 98; if the value of a component is between 128 and 191 inclusive, it should be set to 147; and if the value of a component is between 192 and 255 inclusive, it should be set to 196. In this way, the 256 possible values each component can have is resticted to just 4.
GreyScale
Create an image that has only shades of grey values by computing the average value of the current color's three RGB components and using that average value for all three components of the new color. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (127, 127, 127) for its red, green, and blue components.
Weighted GreyScale
Complete the transformColor method of the WeightedGreyScale color transformer class such that it uses the weights suggested in this article and see if you notice a difference in the image quality. The main idea of the article is to weight the three color components differently, i.e., create a grey scale value based on taking 30% of the red component, 59% of the green component, and 11% of the blue component. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (90, 90, 90) for its red, green, and blue components.

Submitting Your Work

When you are satisfied you have completed the problems above, you should electronically submit your project through Eclipse. A submission is not considered complete unless it includes all the Java code for the project (both what you have written and the code provided when you downloaded the project) and a README file as described here.