Lesson:   Image Processing with Custom Filters

Subject: Using Photoshop's custom filter tool to create local filter operations or masks.
Level: Intermediate
Objectives:  Understanding image processing using local filters; using mathematical operations to explore and modify image features.
Resources: image house.psd and lab report

Background

Earlier, you learned that processing digital images usually involve the use of digital filters. These are operations that transform pixels in a digital image. Because a digital image is represented numerically, these operations are basically mathematical. Photoshop Elements performs these operations automatically. In this activity, you will learn more about how they actually work.

      Digital filters are classified as either global or local. Global filters process each and every pixel in the image uniformly. For example, brightness control can be managed using a global filter that either increases (brightens) or decreases (darkens) pixel values as specified. Local filtering surveys every pixel in the image but transforms them selectively. Specifically, changes to a given pixel are based on its relations with neighboring pixels. For example, sharpening/blurring an image can be done using a local filter that looks for pixels that sit on the border or boundary between objects and/or their backgrounds. Sharpening increases the contrast while blurring reduces it.

      In this activity, you will find out more about image processing using local filtering operations. Specifically, you will experiment with digital filters or masks that perform these and other types of local filtering operations. Before beginning the activities, however, read the short background piece on digital masks. This will explain how masks are organized and function to perform desired effects.

      Tests will be performed using a standard test image (house.psd) available from the University of Southern California's Image Processing Institute. The image represents a moderately complex scene. As you will see, the image has some defects: the resolution is low; it is a little blurred and noisy. We will capitalize on these features during this activity.

      As you proceed through the activities, record your results on the accompanying lab report as directed.

Part One: Getting Started

1.   Start the Application Photoshop and open the image house.psd for inspection. Zoom in the image for a closer inspection.

As you can see, the image is square: 512 X 512 pixels. Select View/Zoom In for a closer look at the pixel structure: 300 or 400% zoom should be sufficient for these purposes. (Hint: the hand tool may be used to scroll the image within the window for better viewing.)

2.   Apply a sharpening filter using the Custom filter tool in the Filter/Other submenu.

Choose Filter/Other/Custom. This reveals the Custom filter as shown below in Figure 1. It allows you to specify the components of a digital filter or mask (as described in the background reading). First, we will employ a sharpening filter to improve the image focus. Fill in the values as shown in Figure 1.

Figure 1. The Custom Filter tool is divided into several components: the center pixel coefficient is surrounded by several neighboring coefficient values (expressed either positively or negatively). The scale indicates the divisor for the sum of the coefficients. The offset value (= 0 here) indicates how far away the neighboring pixels are from the center pixel. The Preview check box can be turned on and off to inspect the image before and after the filtering process has executed.

In this instance, the digital mask has the following structure/organization.

 

–1

 

–1

+5

–1

 

–1

 

scale = 1; offset = 0.

In other words, the value of the center pixel (shaded) is recalculated using the following formula

center pixel     = (–1 X north neighbor value + –1 X east neighbor value + –1 X south neighbor value + –1 X west neighbor value + 5 X center pixel value) / 1

For example, suppose that all of the pixels in the mask have the same values. In this instance, assume that each pixel has the intensity value of 100.

100

100

100

100

100

100

100

100

100

The resulting equation would read

center pixel     = –100 + –100 + –100 + –100 + 500

                        = 500 – 400

                        = 100.

Thus, there would be no change to pixel value. On the other hand, suppose that the values were the following.

100

100

100

100

200

200

100

200

200

Specifically, the center pixel is the corner boundary between dark and lighter areas. The resulting equation would produce

center pixel     = –100 + –200 + –200 + –100 + 1000

                        = 1000 – 600

                        = 400 = 255, i.e., maximum allowed brightness.

Consequently, the pixel is brightened (to the maximum allowed value) to enhance its difference with the surrounding darker pixels. All border pixels would receive similar enhancements. Voila! The result is a sharpened image (using a method similar to unsharp masking).

Part Two: Testing Masks

In this segment, you will test several digital masks in order to explore their effects on our test image. Consult the lab report for recording the results of your tests. Be sure to undo (choose Edit/Undo) the results to restore the image to its original state.

3.   Apply the following mask to the test image. Describe its effect. In what circumstances would this operation be useful?

1

1

1

1

1

1

1

1

1

scale = 9; offset = 0.

(Hint: Once again, zoom in on the image to get a better view of the results. You may also turn the Preview check box off and on in order to see "before" and "after.") Record your answers on the lab report.

4.   Apply the following mask to the test image. Describe its effect. In what circumstances would this operation be useful?

 

–1

 

–1

+20

–1

 

–1

 

scale = 1; offset = 0.

Record your answers on the lab report.

5.   Apply the following mask to the test image. Describe its effect. In what circumstances would this operation be useful?

–1

–1

 

–1

1

1

 

1

1

scale = 1; offset = 0.

(Hint: to understand its effect, try changing the center pixel value to 0 and inspect the corresponding results.) Record your answers on the lab report.

Part Three: Detecting Edges

Local digital filters or masks can be tuned to find pixels that form boundaries between different regions in a digital image. These are called edge elements. Connecting these edge elements can often form a distinct boundary around regions of interest in the image. Thus, detecting edges can be a useful first step for identifying objects in the image.

6.   Apply the following mask to the test image once more.

–1

–1

–1

–1

+8

–1

–1

–1

–1

scale = 1; offset = 0.

As you can see, the filter extracts only potential edge elements while subtracting the rest of the image. How is it able to distinguish these from the other pixels?

7.   The strength of the edge elements can be improved by thresholding. Experiment with threshold values that enhance the visible edges.

Choose Image/Adjustments/Threshold. A threshold tool similar to that in Figure 2 will appear. Adjust the threshold (lower) until the edge elements appear more prominently in the image.

Figure 2. The Threshold tool.

8. Invert the image for better clarity and save it.

Choose Image/Adjustments/Invert. This will produce a negative image of the thresholded version. It should look similar to Figure 3 below. Save it as edgemap.psd for submission.

Figure 3. The inverted edge map image.

This completes the activity.

©J. T. Allen
Exploring the Digital Domain
Last Modified: 2/08.