Question - University of Texas at Austin



Lab Name: Image Manipulation

Purpose: To create a program with various digital image manipulation algorithms in it.

Required Files: JIP.java, ImageEffect.java, InvertEffect.java

Introduction: Many thanks to Professor Calvin Lin of the UTCS department and Walter Chang, a graduate student in the UTCS, for allowing me to us this assignment.

Digital images can be thought of as a 2 dimensional array of pixels. Pixel is short for picture element and they are the tiny boxes of color that make up a digital image. The color of a pixel is normally described by the intensity of red, green, and blue light. A standard format for specify the intensity of each color component is to express it as an integer between 0 and 255. 0 means no

light of that color component and 255 means maximum intensity of that color component. Black consists of 0 red, 0 green, and 0 blue. White consists of 255 red, 255 green, and 255 blue. Different colors are created by varying the intensity of the three primary components.

A digital image can be filtered by altering the original image according to a set algorithm. Consider the following image.

[pic]

Here is the same image after applying an inversion filter.

[pic]

Here is the original image after applying a remove all blue filter.

[pic]

Note the white border has become yellow. Remember whit is all 3 color components (red, green, and blue) at maximum intensity. If the blue is removed that leaves red and green at maximum intensity which results in yellow!

Problem Description:

The program you write will use two distinct representations of images. The first is a BufferedImage which is a class from the Java standard library. This is how a Java program views or represents images on a disk. You don't actually need to know anything about the details of this representation. You are provided a method, imageToPixels(), to convert BufferedImage objects into 2d arrays of pixels. These 2D arrays of pixels are the second way an image is represented in the program. Each pixel is simply a single int that contains encoded information for the intensity of red, blue, and green for that particular pixel. Instead of having to decode that information there are 3 helper methods:

int getRed(int pixel) // get the amount of red in the pixel.

int getGreen(int pixel) // get the amount of green in the pixel.

int getBlue(int pixel) // get the amount of blue in the pixel.

Each of these three method return and int between 0 and 255 inclusive. There is also a helper method to create a pixel based on the amount of red, green, and blue desired.

int makePixel(int red, int green, int blue)

The helper methods are in a class named ImageEffect. This class also handles the conversion between BufferedImage objects and 2D array of ints. There is another class, the JIP class for Java Image Processing, that creates the GUI (graphical user interface) and handles a lot of other low level details like figuring out what image manipulation effects are currently available, opening files, and saving files. You do not have to understand anything about the JIP class other than calling its main method as explained below.

To add an effect you must extend the ImageEffect class. You must create a new class for each effect you add and each one must extend ImageEffect. In each new effect class you must provide two methods. The first is

public int[][] apply(int[][] pixels)

This method has one parameter, a 2d array of ints that represent the pixels of the image. The second is

public String getDescription()

This method returns a short String that describes the effect.

Normally every Java class is contained in its own file. There can actually be multiple classes in on file, but only one of them can be public. The public class must have the same name as the file. The other classes have no visibility modifier on them. When this class is compiled the JIP class will be able to find all the effects regardless if they were public classes are not. (Another of the low level details JIP handles.)

For example here are the two effects shown above. These would be contained in a file named InvertEffect.java.

public class InvertEffect extends ImageEffect {

public int[][] apply(int[][] pixels) {

int numRows = pixels.length;

int numCols = pixels[0].length;

for (int row = 0; row < numRows; row++) {

for (int col = 0; col < numCols; col++) {

pixels[row][col] = ~pixels[row][col];

}

}

return pixels;

}

public String getDescription() {

return "Invert";

}

}// end of class InvertEffect

class RemoveBlue extends ImageEffect

{ public int[][] apply(int[][] pixels)

{ int numRows = pixels.length;

int numCols = pixels[0].length;

int pixel;

for(int row = 0; row < numRows; row++)

{ for(int col = 0; col < numCols; col++)

{ pixel = pixels[row][col];

pixels[row][col] = makePixel( getRed(pixel), getGreen(pixel), 0);

}

}

return pixels;

}

public String getDescription()

{ return "Remove Blue"; }

}// end of class RemoveBlue

To run the program you invoke the main method in the JIP class. If you invoke the main method with no parameters the JIP class will search your computer for classes that extend ImageEffect. You can also call the main method with a single String parameter which is the path name for the location of your compiled classes that extend ImageEffect. This second way of calling the main method may be necessary if you are using certain development environments like BlueJ. The JIP class will create the GUI. Once the GUI is opened you have menus to open and save images and another menu to apply any of the known image effects to the current image.

[pic]

For the standard assignment complete the following effects. Remember, each of these must be in a separate class that extends ImageEffect and provides an apply and getDescription method.

1. NoRed: remove all shades of red from each pixel.

2. NoGreen: remove all shades of green from each pixel.

3. RedOnly: remove all green and blue from each pixel leaving only the shade of red.

4. GreenOnly: remove all red and blue from each pixel leaving only the shade of green.

5. BlueOnly: remove all red and green from each pixel leaving only the shade of blue.

6. BlackAndWhite: Turn a color image into a black and white image. Black, white, and the various shades of gray are achieved by having the same intensity of red, green, and blue. This one requires some thought on how to pick the proper shade of gray.

Extras: Implement the following effects for extra credit.

1. Grow: Create an image that is twice as high and twice as wide as the original picture. Simply map one pixel in the original to 4 pixels in the larger image

2. Shrink: Create an image that is half as high and half as wide as the original. Each pixel value in the smaller image will be the average of 4 pixels from the larger image

3. VerticalReflect: Reflect the image around a vertical line down the middle of the original image. This results in a mirror image. Applying the effect again restores the original image.

4. HorizontalReflect the image around a horizontal line across the middle of the image. The resulting picture will be the original, upside down. Applying this effect again would restore the image to the original.

The following effects are known as neighborhood filters. A pixel in the new image depends not on the original value of that pixel, but on the values of neighboring pixels. For example each pixel in the final image could be the median pixel value among the original pixel value and its 8 neighboring pixels. (above, below, left, right, and the four diagonals.) A special class of a neighborhood filter is a convolution. The neighborhood function of a convolution is linear combination of the pixel values in the neighborhood. A smoothing effect can be achieved by setting each pixel to the average value of itself and its 8 neighbors. The following are some common neighborhood and convolutions:

5. Smooth: Replace each pixel with the average value of a small neighborhood such as the immediate neighbors (a 3 x 3 grid) or something slightly larger like a 5 x 5 or 7 x 7 grid.

6. Sharpen: Light pixels near dark pixels should be made lighter, and dark pixels near light pixels should be made darker. This will highlight neighborhoods of high contrast.

7. De-noise: Replace each pixel with the median value from a small neighborhood.

8. Create your own effect and filter! Investigate various filtering techniques and create effects for them.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download