NAME :

ImageProcessor.java

1.

public static void overlayImage()

{

// Create a new ImageMap object named im with a file as a parameter to the constructor

ImageMap im = new ImageMap("bird.jpg");

// Create a new ImageMap object named overlay with a file as a parameter to the constructor

ImageMap overlay = new ImageMap("overlay.jpg");

//Create a new OverlayFilter Object named io

OverlayFilter io = new OverlayFilter();

// Get the watermarked colors from the filter method in the io object

// providing the colors of im object and overlay object as parameters.

Color[][] watermarked = io.filter(im.getColors(),overlay.getColors());

// Create a new ImageMap named waterMap with the watermarked colors as a parameter to the constructor

ImageMap waterMap = new ImageMap(watermarked);

// Write out the contents of waterMap using the write method, providing a file name parameter

waterMap.write("bird_overlay.jpg");

}

2.

When we construct a new ImageMap Object using String we call read method which search and Reads the File with Name String passed as Parameter and if found is collected all data of the file. Otherwise it simply displays the Error Message.

3.

We use Dot(.) operator to use getColors() because with that we specify which object to use in order to use getColor() function on.

im.getColors() will return the 2d array for colors for object im so we will have to use im.getColors() not just getColors().

4.

In bwImage() we are able to create a ColorFilter Object of type BlackWhiteFilter because the class BlackWhiteFilter is the derived class from ColorFilter and contains all the public methods of class ColorFilter in it.

5.

In Main Method we are able to call both the methods without a dot operator because both the function calls are within the same class. In same Class we don't required dot operator to call methods of same classes.

OverlayFilter.java

1.

OverlayFilter Overlaps both the Images passed to it as Parameters.

2.

averageColors() Methods take two coller properties and averages the values for red, blue, and green and using the new average values create a new color and return it.

3.

Following line of code in Method filter() makes use of averageColor() Method:

newColors[i][j] = averageColors(colors[i][j], overlay[i][j]);

4.

i is counting from beginning of colors object upto end with respect to width of the colors object.

j is counting from beginning of colors object upto end with respect to height of the colors object.

5.

filter method checks for i and j values with respect to overlaywidth and overlayheight in order to only perform color change for the matching values and leave the remaining part of colors as it is because there is no overlap of colors/images.

6.

If i and j values are greater than overlay than we don't need the average of colors as the other image i.e. overlay part is not there so we want the color object to retain its color as it is for no overlay.