# Extension : Extension 1.3: Image Processor (continued)

Authors:

This is a continuation of the previous extension. It’s suggested that you do the previous extension first.

## Directions

The main program you should run for this extension is Background, which conveniently sets up the images in the bar and panels for you to do this work.

So run Background as a Java application. You will see two similar images in the source panels, and some other images in the image bar.

Open the Filters class and begin your work as described below.

### Two more Color filters

You can use if statements for this work.

1. Complete the method bgSubtract so that it returns a Color as follows:

• If the source1Color and source2Color colors are sufficiently similar (within a given tolerance), return Color.BLUE. The idea is to subtract the background so that what is common between the two source images is shown in blue.

We will define a new term for this lab, the Saturation Tolerance. What this tells us is how different two colors can be, and still be considered sufficiently similar. For instance; if the Saturation Tolerance is 10, one color has a red value of 130, and another color has a red value of 138, these would be considered sufficiently similar. But if one color had a red value of 35 and another had a red value of 50, they would not be considered sufficiently similar

• Otherwise, return source1Color.

An example is shown below:

Where the two images are similar, the corresponding pixel in the target image is blue, because your method returned Color.BLUE. Where the images differ, the first image is shown in the target, because your method returned the pixel color from the first image.

2. Complete the method bgReplace that functions as follows:

• If the source1Color is Color.BLUE, then return the source2Color.
• Note that == should NOT be used to check if colors are equal. Rather than doing: color1 == color2 you should do this: color1.equals(color2) (The details and differences between == and .equals() will be covered later in the semester).
• Otherwise, return source1Color.

The effect of this filter is to replace the blue color from the first image with the corresponding pixels from the second image.

To see this work, perform the following steps:

1. Drag the blue-screen image from the target panel and drop it into the leftmost source panel. The GUI should replace what was there with the blue-screen image.

2. Drag the other two-bear picture (the reverse of the one shown in the source panel) from the top icon bar into the middle source panel.

After dragging these images around the GUI, the results should resemble the following:

Note: No transformation is applied yet. The copy operation appears as the menu choice but the Go button was not pressed.

3. Now apply the bgReplace filter, and the results resemble the following:

4. For fun, drag the chicken image from the top icon bar into the middle source panel, and reapply the bgReplace filter. The results should resemble the following:

The chicken is a smaller image, so it did not take up the entire size of the bear image.