• Tidak ada hasil yang ditemukan

116 Chapter 3 Image Enhancement in the Spatial Domain

It is possible in some implementations of image averaging to have negative values when noise is added to an image. In fact, in the example just given, this was precisely the case because Gaussian random variables with zero mean and nonzero variance have negative as well as positive values. The images in the ex- ample were scaled using the second scaling method discussed at the end of the previous section. That is, the minimum value in a given average image was ob- tained and its negative was added to the image. Then all the pixels in the mod- ified image were scaled to the range [0, 255]by multiplying each pixel in the modified image by the quantity 255Max, where Max was the maximum pixel value in that image.

3.5 Basics of Spatial Filtering 117

y

x

Image origin

Mask

Image f(x, y)

w(–1, –1)

f(x-1, y-1) f(x-1, y) f(x-1, y+1)

f(x, y-1) f(x, y) f(x, y+1)

f(x+1, y-1) f(x+1, y) f(x+1, y+1)

w(–1, 0) w(–1, 1)

w(0, –1) w(0, 0) w(0, 1)

w(1, –1) w(1, 0) w(1, 1)

Mask coefficients, showing coordinate arrangement

Pixels of image section under mask

FIGURE 3.32 The mechanics of spatial filtering.

The magnified drawing shows a 3*3 mask and the image section directly under it;

the image section is shown

displaced out from under the mask for ease of readability.

In general, linear filtering of an image fof size M*Nwith a filter mask of size m*nis given by the expression:

(3.5-1) where, from the previous paragraph,a=(m-1)2and b=(n-1)2. To generate a complete filtered image this equation must be applied for x=0, 1, 2,p,M-1and y=0, 1, 2,p,N-1. In this way, we are assured that the

g(x, y) = a

a s= -a a

b t= -b

w(s, t)f(x + s, y + t)

GONZ03-075-146.II 29-08-2001 13:43 Page 117

118 Chapter 3 Image Enhancement in the Spatial Domain

mask processes all pixels in the image. It is easily verified when m=n=3that this expression reduces to the example given in the previous paragraph.

As discussed in Chapter 4, the process of linear filtering given in Eq. (3.5-1) is similar to a frequency domain concept called convolution. For this reason, linear spatial filtering often is referred to as “convolving a mask with an image.”

Similarly, filter masks are sometimes called convolution masks. The term con- volution kernelalso is in common use.

When interest lies on the response,R, of an m*nmask at any point (x, y), and not on the mechanics of implementing mask convolution, it is common practice to simplify the notation by using the following expression:

(3.5-2)

where the w’s are mask coefficients, the z’s are the values of the image gray levels corresponding to those coefficients, and mnis the total number of coef- ficients in the mask. For the 3*3 general mask shown in Fig. 3.33 the response at any point (x, y)in the image is given by

(3.5-3)

We make special mention of this simple formula because it is seen frequently in the published literature on image processing.

Nonlinear spatial filters also operate on neighborhoods, and the mechanics of sliding a mask past an image are the same as was just outlined. In general, however, the filtering operation is based conditionally on the values of the pix- els in the neighborhood under consideration, and they do not explicitly use co- efficients in the sum-of-products manner described in Eqs. (3.5-1) and (3.5-2).

As shown in Section 3.6.2, for example, noise reduction can be achieved effec- tively with a nonlinear filter whose basic function is to compute the median gray-level value in the neighborhood in which the filter is located. Computation of the median is a nonlinear operation, as is computation of the variance, which we used in Section 3.3.4.

= a

9 i=1

wizi.

R = w1z1 + w2z2 + pw9z9

= a

mn i=1

wizi

R = w1z1 + w2z2 + p + wmnzmn

w1 w2 w3

w4 w5 w6

w7 w8 w9

FIGURE 3.33 Another

representation of a general 3*3 spatial filter mask.

GONZ03-075-146.II 29-08-2001 13:43 Page 118

3.6 Smoothing Spatial Filters 119 An important consideration in implementing neighborhood operations for

spatial filtering is the issue of what happens when the center of the filter ap- proaches the border of the image. Consider for simplicity a square mask of size n*n. At least one edge of such a mask will coincide with the border of the image when the center of the mask is at a distance of (n-1)2pixels away from the border of the image. If the center of the mask moves any closer to the border, one or more rows or columns of the mask will be located outside the image plane. There are several ways to handle this situation. The simplest is to limit the excursions of the center of the mask to be at a distance no less than (n-1)2pixels from the border. The resulting filtered image will be smaller than the original, but all the pixels in the filtered imaged will have been processed with the full mask. If the result is required to be the same size as the original, then the approach typically employed is to filter all pixels only with the section of the mask that is fully contained in the image. With this approach, there will be bands of pixels near the border that will have been processed with a partial filter mask. Other approaches include “padding” the image by adding rows and columns of 0’s (or other constant gray level), or padding by replicat- ing rows or columns. The padding is then stripped off at the end of the process.

This keeps the size of the filtered image the same as the original, but the values of the padding will have an effect near the edges that becomes more prevalent as the size of the mask increases. The only way to obtain a perfectly filtered re- sult is to accept a somewhat smaller filtered image by limiting the excursions of the center of the filter mask to a distance no less than (n-1)2pixels from the border of the original image.