613 19 IMAGE DETECTION AND REGISTRATION This chapter covers two related image analysis tasks: detection and registration. Image detection is concerned with the determination of the presence or absence of objects suspected of being in an image. Image registration involves the spatial align- ment of a pair of views of a scene. 19.1. TEMPLATE MATCHING One of the most fundamental means of object detection within an image field is by template matching, in which a replica of an object of interest is compared to all unknown objects in the image field (1–4). If the template match between an unknown object and the template is sufficiently close, the unknown object is labeled as the template object. As a simple example of the template-matching process, consider the set of binary black line figures against a white background as shown in Figure 19.1-1a. In this example, the objective is to detect the presence and location of right triangles in the image field. Figure 19.1-1b contains a simple template for localization of right trian- gles that possesses unit value in the triangular region and zero elsewhere. The width of the legs of the triangle template is chosen as a compromise between localization accuracy and size invariance of the template. In operation, the template is sequen- tially scanned over the image field and the common region between the template and image field is compared for similarity. A template match is rarely ever exact because of image noise, spatial and ampli- tude quantization effects, and a priori uncertainty as to the exact shape and structure of an object to be detected. Consequently, a common procedure is to produce a difference measure between the template and the image field at all points of Dmn,() Digital Image Processing: PIKS Inside, Third Edition. William K. Pratt Copyright © 2001 John Wiley & Sons, Inc. ISBNs: 0-471-37407-5 (Hardback); 0-471-22132-5 (Electronic) 614 IMAGE DETECTION AND REGISTRATION the image field where and denote the trial offset. An object is deemed to be matched wherever the difference is smaller than some established level . Normally, the threshold level is constant over the image field. The usual difference measure is the mean-square difference or error as defined by (19.1-1) where denotes the image field to be searched and is the template. The search, of course, is restricted to the overlap region between the translated template and the image field. A template match is then said to exist at coordinate if (19.1-2) Now, let Eq. 19.1-1 be expanded to yield (19.1-3) FIGURE 19.1-1. Template-matching example. M– mM≤≤ N– nN≤≤ L D mn,() Dmn,() Fjk,()Tj mk n–,–()–[] 2 k ∑ j ∑ = Fjk,() Tjk,() mn,() Dmn,()L D mn,()< Dmn,()D 1 mn,()2D 2 mn,()D 3 mn,()+–= TEMPLATE MATCHING 615 where (19.1-4a) (19.1-4b) (19.1-4c) The term represents a summation of the template energy. It is constant valued and independent of the coordinate . The image energy over the window area represented by the first term generally varies rather slowly over the image field. The second term should be recognized as the cross correlation between the image field and the template. At the coordinate location of a template match, the cross correlation should become large to yield a small differ- ence. However, the magnitude of the cross correlation is not always an adequate measure of the template difference because the image energy term is posi- tion variant. For example, the cross correlation can become large, even under a con- dition of template mismatch, if the image amplitude over the template region is high about a particular coordinate . This difficulty can be avoided by comparison of the normalized cross correlation (19.1-5) to a threshold level . A template match is said to exist if (19.1-6) The normalized cross correlation has a maximum value of unity that occurs if and only if the image function under the template exactly matches the template. One of the major limitations of template matching is that an enormous number of templates must often be test matched against an image field to account for changes in rotation and magnification of template objects. For this reason, template matching is usually limited to smaller local features, which are more invariant to size and shape variations of an object. Such features, for example, include edges joined in a Y or T arrangement. D 1 mn,() Fjk,()[] 2 k ∑ j ∑ = D 2 mn,() Fjk,()Tj mk n–,–()[] k ∑ j ∑ = D 3 mn,() Tj mk n–,–()[] 2 k ∑ j ∑ = D 3 mn,() mn,() D 1 mn,() R FT mn,() D 1 mn,() mn,() R ˜ FT mn,() D 2 mn,() D 1 mn,() Fjk,()Tj mk n–,–()[] k ∑ j ∑ Fjk,()[] 2 k ∑ j ∑ == L R mn,() R ˜ FT mn,()L R mn,()> 616 IMAGE DETECTION AND REGISTRATION 19.2. MATCHED FILTERING OF CONTINUOUS IMAGES Matched filtering, implemented by electrical circuits, is widely used in one-dimen- sional signal detection applications such as radar and digital communication (5–7). It is also possible to detect objects within images by a two-dimensional version of the matched filter (8–12). In the context of image processing, the matched filter is a spatial filter that pro- vides an output measure of the spatial correlation between an input image and a ref- erence image. This correlation measure may then be utilized, for example, to determine the presence or absence of a given input image, or to assist in the spatial registration of two images. This section considers matched filtering of deterministic and stochastic images. 19.2.1. Matched Filtering of Deterministic Continuous Images As an introduction to the concept of the matched filter, consider the problem of detecting the presence or absence of a known continuous, deterministic signal or ref- erence image in an unknown or input image corrupted by additive stationary noise independent of . Thus, is composed of the signal image plus noise, (19.2-1a) or noise alone, (19.2-1b) The unknown image is spatially filtered by a matched filter with impulse response and transfer function to produce an output (19.2-2) The matched filter is designed so that the ratio of the signal image energy to the noise field energy at some point in the filter output plane is maximized. The instantaneous signal image energy at point of the filter output in the absence of noise is given by (19.2-3) Fxy,() F U xy,() Nxy,() Fxy,() F U xy,() F U xy,()Fxy,()Nxy,()+= F U xy,()Nxy,()= Hxy,() H ω x ω y ,() F O xy,()F U xy,() ᭺ ء Hxy,()= εη,() εη,() S εη,() 2 Fxy,() ᭺ ء Hxy,() 2 = MATCHED FILTERING OF CONTINUOUS IMAGES 617 with and . By the convolution theorem, (19.2-4) where is the Fourier transform of . The additive input noise com- ponent is assumed to be stationary, independent of the signal image, and described by its noise power-spectral density . From Eq. 1.4-27, the total noise power at the filter output is (19.2-5) Then, forming the signal-to-noise ratio, one obtains (19.2-6) This ratio is found to be maximized when the filter transfer function is of the form (5,8) (19.2-7) If the input noise power-spectral density is white with a flat spectrum, , the matched filter transfer function reduces to (19.2-8) and the corresponding filter impulse response becomes (19.2-9) In this case, the matched filter impulse response is an amplitude scaled version of the complex conjugate of the signal image rotated by 180°. For the case of white noise, the filter output can be written as (19.2-10a) x ε= y η= S εη,() 2 F ω x ω y ,()H ω x ω y ,()i ω x εω y η+(){}exp ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ 2 = F ω x ω y ,() Fxy,() Nxy,() W N ω x ω y ,() N W N ω x ω y ,()H ω x ω y ,() 2 ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ = S εη,() 2 N F ω x ω y ,()H ω x ω y ,()i ω x εω y η+(){}exp ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ 2 W N ω x ω y ,()H ω x ω y ,() 2 ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ = H ω x ω y ,() F * ω x ω y ,() i ω x εω y η+()–{}exp W N ω x ω y ,() = W N ω x ω y ,()n w 2⁄= H ω x ω y ,() 2 n w F * ω x ω y ,() i ω x εω y η+()–{}exp= Hxy,() 2 n w F* ε x– η y–,()= F O xy,() 2 n w F U xy,() ᭺ ء F ∗ ε x– η y–,()= 618 IMAGE DETECTION AND REGISTRATION or (19.2-10b) If the matched filter offset is chosen to be zero, the filter output (19.2-11) is then seen to be proportional to the mathematical correlation between the input image and the complex conjugate of the signal image. Ordinarily, the parameters of the matched filter transfer function are set to be zero so that the origin of the output plane becomes the point of no translational offset between and . If the unknown image consists of the signal image translated by dis- tances plus additive noise as defined by (19.2-12) the matched filter output for , will be (19.2-13) A correlation peak will occur at , in the output plane, thus indicating the translation of the input image relative to the reference image. Hence the matched filter is translation invariant. It is, however, not invariant to rotation of the image to be detected. It is possible to implement the general matched filter of Eq. 19.2-7 as a two-stage linear filter with transfer function (19.2-14) The first stage, called a whitening filter, has a transfer function chosen such that noise with a power spectrum at its input results in unit energy white noise at its output. Thus (19.2-15) F O xy,() 2 n w F U αβ,()F ∗ αεx–+ βηy–+,()αd βd ∞ – ∞ ∫ ∞ – ∞ ∫ = εη,() F O xy,() 2 n w F U αβ,()F ∗ α x– β y–,()αd βd ∞ – ∞ ∫ ∞ – ∞ ∫ = εη,() F U xy,() Fxy,() F U xy,() ∆x ∆y,() F U xy,()Fx ∆x+ y ∆y+,()Nxy,()+= ε 0= η 0= F O xy,() 2 n w F α∆x+ β∆y+,()Nxy,()+[]F ∗ α x– β y–,()αd βd ∞ – ∞ ∫ ∞ – ∞ ∫ = x ∆x= y ∆y= H ω x ω y ,()H A ω x ω y ,()H B ω x ω y ,()= Nxy,() W N ω x ω y ,() W N ω x ω y ,()H A ω x ω y ,() 2 1= MATCHED FILTERING OF CONTINUOUS IMAGES 619 The transfer function of the whitening filter may be determined by a spectral factor- ization of the input noise power-spectral density into the product (7) (19.2-16) such that the following conditions hold: (19.2-17a) (19.2-17b) (19.2-17c) The simplest type of factorization is the spatially noncausal factorization (19.2-18) where represents an arbitrary phase angle. Causal factorization of the input noise power-spectral density may be difficult if the spectrum does not factor into separable products. For a given factorization, the whitening filter transfer func- tion may be set to (19.2-19) The resultant input to the second-stage filter is , where represents unit energy white noise and (19.2-20) is a modified image signal with a spectrum (19.2-21) From Eq. 19.2-8, for the white noise condition, the optimum transfer function of the second-stage filter is found to be W N ω x ω y ,()W N + ω x ω y ,()W N – ω x ω y ,()= W N + ω x ω y ,()W N – ω x ω y ,()[] ∗ = W N – ω x ω y ,()W N + ω x ω y ,()[] ∗ = W N ω x ω y ,()W N + ω x ω y ,() 2 W N – ω x ω y ,() 2 == W N + ω x ω y ,()W N ω x ω y ,()iθω x ω y ,(){}exp= θω x ω y ,() H A ω x ω y ,() 1 W N + ω x ω y ,() = F 1 xy,()N W xy,()+ N W xy,() F 1 xy,()Fxy,() ᭺ ء H A xy,()= F 1 ω x ω y ,()F ω x ω y ,()H A ω x ω y ,() F ω x ω y ,() W N + ω x ω y ,() == 620 IMAGE DETECTION AND REGISTRATION (19.2-22) Calculation of the product shows that the optimum filter expression of Eq. 19.2-7 can be obtained by the whitening filter implementation. The basic limitation of the normal matched filter, as defined by Eq. 19.2-7, is that the correlation output between an unknown image and an image signal to be detected is primarily dependent on the energy of the images rather than their spatial structure. For example, consider a signal image in the form of a bright hexagonally shaped object against a black background. If the unknown image field contains a cir- cular disk of the same brightness and area as the hexagonal object, the correlation function resulting will be very similar to the correlation function produced by a per- fect match. In general, the normal matched filter provides relatively poor discrimi- nation between objects of different shape but of similar size or energy content. This drawback of the normal matched filter is overcome somewhat with the derivative matched filter (8), which makes use of the edge structure of an object to be detected. The transfer function of the pth-order derivative matched filter is given by (19.2-23) where p is an integer. If p = 0, the normal matched filter (19.2-24) is obtained. With p = 1, the resulting filter (19.2-25) is called the Laplacian matched filter. Its impulse response function is (19.2-26) The pth-order derivative matched filter transfer function is (19.2-27) H B ω x ω y ,() F * ω x ω y ,() W N – ω x ω y ,() i ω x εω y η+()–{}exp= H A ω x ω y ,()H B ω x ω y ,() H p ω x ω y ,() ω x 2 ω y 2 +() p F * ω x ω y ,()i ω x εω y η+() –{}exp W N ω x ω y ,() = H 0 ω x ω y ,() F * ω x ω y ,() i ω x εω y η+() –{}exp W N ω x ω y ,() = H p ω x ω y ,()ω x 2 ω y 2 +()H 0 ω x ω y ,()= H 1 xy,() x 2 ∂ ∂ y 2 ∂ ∂ + ᭺ ء H 0 xy,()= H p ω x ω y ,()ω x 2 ω y 2 +() p H 0 ω x ω y ,()= MATCHED FILTERING OF CONTINUOUS IMAGES 621 Hence the derivative matched filter may be implemented by cascaded operations consisting of a generalized derivative operator whose function is to enhance the edges of an image, followed by a normal matched filter. 19.2.2. Matched Filtering of Stochastic Continuous Images In the preceding section, the ideal image to be detected in the presence of additive noise was assumed deterministic. If the state of is not known exactly, but only statistically, the matched filtering concept can be extended to the detection of a stochastic image in the presence of noise (13). Even if is known deterministically, it is often useful to consider it as a random field with a mean . Such a formulation provides a mechanism for incorpo- rating a priori knowledge of the spatial correlation of an image in its detection. Con- ventional matched filtering, as defined by Eq. 19.2-7, completely ignores the spatial relationships between the pixels of an observed image. For purposes of analysis, let the observed unknown field (19.2-28a) or noise alone (19.2-28b) be composed of an ideal image , which is a sample of a two-dimensional sto- chastic process with known moments, plus noise independent of the image, or be composed of noise alone. The unknown field is convolved with the matched filter impulse response to produce an output modeled as (19.2-29) The stochastic matched filter is designed so that it maximizes the ratio of the aver- age squared signal energy without noise to the variance of the filter output. This is simply a generalization of the conventional signal-to-noise ratio of Eq. 19.2-6. In the absence of noise, the expected signal energy at some point in the output field is (19.2-30) By the convolution theorem and linearity of the expectation operator, (19.2-31) Fxy,() Fxy,() Fxy,() EFxy,(){}Fxy,()= F U xy,()Fxy,()Nxy,()+= F U xy,()Nxy,()= Fxy,() Nxy,() Hxy,() F O xy,()F U xy,() ᭺ ء Hxy,()= εη,() S εη,() 2 EFxy,(){} ᭺ ء Hxy,() 2 = S εη,() 2 E F ω x ω y ,(){}H ω x ω y ,()i ω x εω y η+(){}exp ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ 2 = 622 IMAGE DETECTION AND REGISTRATION The variance of the matched filter output, under the assumption of stationarity and signal and noise independence, is (19.2-32) where and are the image signal and noise power spectral densities, respectively. The generalized signal-to-noise ratio of the two equations above, which is of similar form to the specialized case of Eq. 19.2-6, is maximized when (19.2-33) Note that when is deterministic, Eq. 19.2-33 reduces to the matched filter transfer function of Eq. 19.2-7. The stochastic matched filter is often modified by replacement of the mean of the ideal image to be detected by a replica of the image itself. In this case, for , (19.2-34) A special case of common interest occurs when the noise is white, , and the ideal image is regarded as a first-order nonseparable Markov process, as defined by Eq. 1.4-17, with power spectrum (19.2-35) where is the adjacent pixel correlation. For such processes, the resultant modified matched filter transfer function becomes (19.2-36) At high spatial frequencies and low noise levels, the modified matched filter defined by Eq. 19.2-36 becomes equivalent to the Laplacian matched filter of Eq. 19.2-25. N W F ω x ω y ,()W N ω x ω y ,()+[]H ω x ω y ,() 2 ω x d ω y d ∞ – ∞ ∫ ∞ – ∞ ∫ = W F ω x ω y ,()W N ω x ω y ,() H ω x ω y ,() E F * ω x ω y ,() {}i ω x εω y η+() –{}exp W F ω x ω y ,()W N ω x ω y ,()+ = Fxy,() εη0== H ω x ω y ,() F * ω x ω y ,() W F ω x ω y ,()W N ω x ω y ,()+ = W N ω x ω y ,()n W 2⁄= W F ω x ω y ,() 2 α 2 ω x 2 ω y 2 ++ = α–{}exp H ω x ω y ,() 2 α 2 ω x 2 ω y 2 ++() F * ω x ω y ,() 4 n W α 2 ω x 2 ω y 2 ++()+ =