• Aucun résultat trouvé

Box filters

Dans le document HANDBOOK OF COMPUTER VISION AND APPLICATIONS (Page 183-188)

Elementary Spatial Processing

7.3 Box filters

15

Figure 7.1: Transfer functions of type I box filters with 3, 7, and 15 coefficients inaa linear plot; andba log-log plot of the absolute value.

This feature shows the central importance of the Gaussian function for signal processing from yet another perspective.

To a good approximation, the Gaussian function can be replaced on orthogonal discrete lattices by the binomial distribution. The coef-ficients of a 1-D binomal filter withR+1 coefficients and its transfer function are given by

BR = 1 2R

"

b0=1, . . . , br = R r

!

, . . . , bR+1=1

#

⇐⇒BˆR(k)˜ =cosR(πk/2)˜ (7.16) With the comments on the isotropy of discrete filters in mind (Sec-tion7.2.2), it is necessary to study the deviation of the transfer function of binomial filters from an isotropic filter.

7.3 Box filters

The simplest method is to average pixels within the filter mask and to divide the sum by the number of pixels. Such a simple filter is called a box filter. It is also known under the name running mean. In this section, type I (Section7.3.1) and type II (Section7.3.2) box filters and box filters on hexagonal lattices (Section7.3.3) are discussed.

7.3.1 Type I box filters

The simplest type I 1-D box filter is

3R=1

3[1,1,1]⇐⇒3R(ˆ ˜k)=1 3+

2

3cos(π˜k) (7.17) The factor 1/3 scales the result of the convolution sum in order to preserve the mean value (see Eq. (7.1) in Section 7.2.1). Generally, a

type I 1-D box filter with 2R+1 coefficients has the transfer function

IR(ˆ k)˜ = 1 2R+1+

2 2R+1

XR r=1

cos(πr˜k)

= 1

2R+1

cos(πRk)˜ cos(π(R+1)k)˜ 1cos(πk)˜

(7.18)

For small wave numbers the transfer function can be approximated by

IR(ˆ k)˜ 1−R(R+1)

6 (πk)˜ 2+R(R+1)(3R2+3R1)

360 ˜k)4 (7.19) Figure7.1shows that the box filter is a poor averaging filter. The trans-fer function is not monotonical and the envelope of the transtrans-fer func-tion is only decreasing with k1 (compare Section 3.2.3). The high-est wave number is not completely suppressed even with large filter masks. The box filter also shows significant oscillations in the trans-fer function. The filter2R+1Rcompletely eliminates the wave numbers

˜k= 2r /(2R+1)for 1 ≤r ≤R. In certain wave-number ranges, the transfer function becomes negative. This corresponds to a 180° phase shift and thus a contrast inversion.

Despite all their disadvantages, box filters have one significant ad-vantage. They can be computed very fast with only one addition, sub-traction, and multiplication independent of the size of the filter, that is,O(R0). Equation (7.18) indicates that the box filter can also be un-derstood as a filter operation with a recursive part according to the following relation:

gn0 =g0n1+ 1

2R+1(gn+R−gnR1) (7.20) This recursion can easily be understood by comparing the computa-tions for the convolution at neighboring pixels. When the box mask is moved one position to the right, it contains the same weighting fac-tor for all pixels except for the last and the first pixel. Thus, we can simply take the result of the previous convolution,(g0n1), subtract the first pixel that just moved out of the mask,(gnR1), and add the gray value at the pixel that just came into the mask,(gn+R). In this way, the computation of a box filter does not depend on its size.

Higher-dimensional box filters can simply be computed by cascad-ing 1-D box filters runncascad-ing in all directions, as the box filter is separable.

Thus the resulting transfer function for aD-dimensional filter is

2R+1R(ˆ k)˜ = 1 (2R+1)D

YD d=1

cos(πRk˜d)−cos(π(R+1)˜kd)

1cos(πk˜d) (7.21)

a

k~ ppppf

b

k~

ppppf

c

k~ ppppf

d

k~

ppppf

Figure 7.2: Absolute deviation of the 2-D transfer functions of type I 2-D box filters from the transfer function along thexaxis (1-D transfer function shown in Fig.7.1) for aa3×3,b5×5,c7×7, andda3R(ˆ ˜k)filter running in 0°, 60°, and 120° on a hexagonal grid. The distance of the contour lines is 0.05 ina -cand 0.01 in d. The area between the thick contour lines marks the range around zero.

For a 2-D filter, we can approximate the transfer function for small wave numbers and express the result in cylinder coordinates by using k1=kcosφandk2=ksinφand obtain

IR(ˆ k)˜ 1−R(R+1)

6 ˜k)2+R(R+1)(14R2+14R1) 1440 (πk)˜ 4

R(R+1)(2R2+2R+1)

1440 cos(4φ)(πk)˜ 4

(7.22)

a

k~ 2

6 14

b

k~ 2 6

14

Figure 7.3: Transfer functions of type II box filters with 2, 6, and 14 coefficients inaa linear plot; andba log-log plot of the absolute value.

This equation indicates that—although the term with ˜k2 is isotropic—

the term with ˜k4 is significantly anisotropic. The anisotropy does not improve for larger filter masks because the isotropic and anisotropic terms in ˜k4 grow with the same power inR.

A useful measure for the anisotropy is the deviation of the 2-D filter response from the response in the direction of thex1axis:

R(ˆ k)˜ =R(ˆ ˜k)−R(ˆ ˜k1) (7.23) For an isotropic filter, this deviation is zero. Again in an approximation for small wave numbers we obtain by Taylor expansion

IR(ˆ ˜k) 2R4+4R3+3R2+R

720 sin2(2φ)(π˜k)4 (7.24) The anisotropy for various box filters is shown in Fig.7.2a–c. Clearly, the anisotropy does not become weaker for larger box filters. The de-viations are significant and easily reach 0.25. This figure means that the attenuation for a certain wave number varies up to 0.25 with the direction of the wave number.

7.3.2 Type II box filters

Type II box filters have an even number of coefficients in every direction.

Generally, a type II 1-D box filter with 2R coefficients has the transfer function

IIR(ˆ k)˜ = 1 R

XR r=1

cos(π(r1/2)k)˜

= 1 2R

cos(π(R1/2)k)˜ cos(π(R+1/2)k)˜ 1cos(π˜k)

(7.25)

For small wave numbers the transfer function can be approximated by

IIR(ˆ ˜k)≈14R21

24 ˜k)2+48R440R2+7

5760 ˜k)4 (7.26) Figure7.3also shows that type II box filter are poor averaging filters.

Their only advantage over type I box filters is that as a result of the even number of coefficients the transfer function at the highest wave number is always zero.

Higher-dimensional type II box filters are formed in the same way as type I filters in Eq. (7.21). Thus we investigate here only the anisotropy of type II filters in comparison to type I filters. The transfer function of a 2-D filter can be approximated for small wave numbers in cylinder coordinates by

IIR(ˆ ˜k) 14R21

24 (πk)˜ 2+(4R21)(28R213) 11520 ˜k)4

(4R21)(4R2+1)

11520 cos(4φ)(π˜k)4

(7.27)

and the anisotropy according to Eq. (7.23) is given by

IIR(ˆ k)˜ 16R41

5760 sin2(2φ)(π˜k)4 (7.28) A comparison with Eq. (7.24) shows—not surprisingly—that the ani-sotropy of type I and type II filters is essentially the same.

7.3.3 Box filters on hexagonal lattices

On a hexagonal lattice (Section2.3.1) a separable filter is running not in two but in three directions: 0°, 60°, and 120° with respect to thexaxis.

Thus the transfer function of a separable filter is composed of three factors:

hR(ˆ k)˜ = 1 (2R+1)3 ·

cos(πR˜k1)−cos(π(R+1)k˜1) 1cos(πk˜1)

cos(πR(k2+k˜1)/2)−cos(π(R+1)(k2+k˜1)/2) 1cos(π(k2+k˜1)/2)

cos(πR(k2−k˜1)/2)−cos(π(R+1)(k2−k˜1)/2) 1cos(π(k2−k˜1)/2)

(7.29)

As for the box filters on a rectangular lattice (Eqs. (7.24) and (7.28)), we compute the anisotropy of the filter using Eq. (7.23) in the approxima-tion for small wave numbers. The result is

hR(ˆ k)˜ 3R+15R2+40R3+60R4+48R5+16R6

241920 sin2(3φ)(π˜k)6 (7.30)

a

k~ 4 2

8 16 32

b

k~ 32 8

2 16 4

Figure 7.4: Transfer functions of binomial filtersBRinaa linear plot andba log-log plot of the absolute value with values ofRas indicated.

This equation indicates that the effects of anisotropy are significantly lower on hexagonal grids. In contrast to the box filters on a square grid, there is only an anisotropic term with ˜k6and not already with ˜k4. From Fig.7.2a and d we can conclude that the anisotropy is about a factor of 5 lower for a3Rfilter on a hexagonal lattice than on a square lattice.

7.4 Binomial filters

Dans le document HANDBOOK OF COMPUTER VISION AND APPLICATIONS (Page 183-188)