Question 4 - Filtering

advertisement
Question 4 – Filtering
(Spatial, Frequency, Liner, Non-linear)
1. Spatial Filtering - background
The use of spatial masks for image processing usually is called spatial filtering (as opposed to
frequency domain filtering using the Fourier transform) and the masks themselves are called spatial
filters.
Now we consider linear and non-linear spatial filters for image enhancement.
Liner filters are based on concept that the transfer function and impulse function of a linear system are
inverse Fourier Transform of each other.
Low-pass filters attenuate or eliminate high-frequency components in the Fourier domain while leaving
low frequencies untouched. High-frequency components characterize edges and other sharp details in
an image, so the net effect of low-pass filtering is image blurring.
High-pass filters attenuate or eliminate low-frequency components. Low-frequency components are
responsible for the slowly varying characteristics of an image, such as overall contrast and average
intensity, and the net result of high-pass filtering is a reduction of these features and a correspondingly
apparent sharpening of edges and other sharp details.
Band-pass filtering removes selected frequency regions between low and high frequencies. These
filters are used for image restoration and are seldom of interest in image enhancement.
Figure 1. Top: Cross sections of basic shapes for circularly symmetric frequency domain filters.
Bottom: cross sections of corresponding spatial domain filters
1
The above figure 1 shows the cross sections of circularly symmetric lowpass, highpass, and bandpass
filters in the frequency domain and their corresponding spatial filters. The shapes in the bottom row are
used as guidelines for specifying linear spatial filters. Regardless of the type of linear filter used,
however, the basic approach is to sum products between the mask coefficients and the intensities of the
pixels under the mask at a specific location in the image.
Figure 2 below shows the a general 3 x 3 mask.
w1
w4
w7
w2
w5
w8
w3
w6
w9
Figure 2. A 3 x 3 mask with arbitrary coefficients
Denoting the gray-level of pixels under the mask at any location by z1, z2, …., z9, the response of a
linear mask is
R = w1 z1 + w2z2 + …. w9 z9 -------- (Equation 1)
If the centre of the mask is at location (x,y) [as shown in figure 4.1, page 162] in the image, the gray
level of pixel located at (x,y) is replaced by R. The mask is then moved to the next pixel location in the
image and the process is repeated. This continues till all pixel locations have been covered. The value
of R is computed by using partial neighborhoods for pixels that are located in the border of the image.
Also, usual practice is to create a new image to store the values of R, instead of changing pixels values
in place. This practice avoids using gray-level that have been altered as a result of an earlier application
of this equation.
1.1 Smoothing Filters
Smoothing filters are used for blurring and for noise reduction. Blurring is used in preprocessing steps,
such as removal of small details from an image prior to (large) object extraction. And bridging of small
gaps in lines or curves. Noise reduction can be accomplished by blurring with a linear filter and also by
nonlinear filtering.
1.1.1
Lowpass Spatial Filtering
The shape of impulse response needed to implement a lowpass (smoothing) spatial filter indicates that
the filter has to have all positive coefficients (as shown in Fig 1(a)). Although the spatial filter shape
shown in Fig 1(a) could be modeled by, say, a sampled Gaussian function, the key requirement is that
all the coefficients be positive.
For a 3 x 3 spatial filter, the simplest arrangement would be a mask in which all coefficients have a
value of 1. However from equation 1, the response would then be the sum of gray levels for nine pixels,
2
which would cause R to be out of the valid gray-level range. The solution is to scale the sum by
dividing R by 9.
Figure 3. Spatial Lowpass filters of various sizes
Figure 3 shows an example of blurring by successively larger smoothing masks.
3
Figure 4. Original image; (b-f) results of spatial lowpass filtering with a mask of size n x n, n = 3, 5, 7,
15, 25.
1.1.2 Median Filtering
If the objective is to achieve noise reduction rather than blurring, an alternative approach is to use
median filters. That is, the gray-level of each pixel is replaced by the median of the gray levels in a
neighborhood of that pixel, instead of by the average. This method is particularly effective when the
noise pattern consists of strong, spike like components and the characteristics to be preserved is edge
sharpness.
Figure 5. (a) Original image; (b) image corrupted by impulse noise; (c) result of 5 x 5 neighborhood
averaging; (d) result of 5 x 5 medium filtering.
1.2 Sharpening Filters
Sharpening filters are used to highlight fine detail in an image or to enhance detail that has been
blurred. Use of image sharpening vary and include applications ranging from electronic printing and
medical imaging to industrial inspection and autonomous target detection in smart weapons.
1.2.1
Basic highpass spatial filtering
The shape of the impulse response needed to implement a highpass (sharpening) spatial filter indicates
that the filter should have positive coefficients near its center, and negative coefficients in the outer
periphery (as shown in Fig 1(b)). For a 3 x 3 mask, choosing a positive value in the centre location with
negative coefficients in the rest of the mask meets this condition.
Figure below (fig 3) shows the classic implementation of a 3 x 3 sharpening filter.
1/9 x
-1
-1
-1
-1
8
-1
-1
-1
-1
Figure 3. A basic highpass spatial filter
4
Figure 5. (a) Image of a human retina; (b) highpass filtered result
1.2.2
High-boost Filtering
A highpass filtered image may be computed as the difference between the original image and a lowpass
filtered version of that image; that is,
Highpass = Original – Lowpass
1.2.3 Derivative Filters
Averaging of pixels over a region tends to blur detail in an image. As averaging is analogous to
integration, differentiation can be expected to have the opposite effect and thus sharpen an image.
The most common method of differentiation in image processing applications is the gradient.
2. Enhancement in the Frequency Domain
We simply compute the Fourier transform of the image to be enhanced, multiple the result by a filter
transfer function and take the inverse transform to produce the enhanced image.
2.1 Lowpass Filtering
As indicated earlier, edges and other sharp transitions (such as noise) in the gray level of an image
contribute significantly to the high-frequency content of its Fourier transform. Hence blurring
5
(smoothing) is achieved in the frequency domain by attenuating a specified range of high-frequency
components in the transform of a given image.
G(u,v) = H(u,v)F(u,v) ------- (Equation 2)
Where F(u,v) is the Fourier transform of an image to be smoothed. The problem is to select a filter
transform function H(u,v) that yields G(u,v) by attenuating the high-frequency components of F(u,v).
The inverse transform will then yield the desired smoothed image g(x,y).
In the following discussion we discuss the filter transfer functions that affect the real and imaginary
parts of F(u,v). Such filters are referred to as zero-phase-shift filters, because they do not alter the phase
of the transform.
2.1.1 Ideal Filter
A 2-D ideal lowpass filter (ILPF) is one whose transfer function satisfies the relation
1...if ...D(u, v)  D0
H (u, v)  
 0..if ...D(u, v)  D0
(Equation 3)
Where D0 is a specified nonnegative quantity and D(u,v) is the distance from point (u,v) to the origin of
the frequency plane; that is,
D(u,v) = (u2 + v2)1/2 ------- (Equation 4)
Figure 4.30(a) shows a 3-D perspective plot of H(u,v) as a function of u and v.
Figure 6. (a) Perspective plot of an ideal lowpass filter transfer function; (b) filter cross section.
The name ideal filter indicates that all frequencies inside a circle of radius D0 are passed with no
attenuation, whereas all frequencies outside this circle are completely attenuated.
2.1.2 Butterworth Filter
6
The transfer function of the Butterworth lowpass filter (BLPF) of order n and with cutoff frequency
locus at a distance D0 from the origin is defined by the relation
H (u.v) 
1
1  D(u, v) / D0 
2n
------- (Equation 5)
Where D(u,v) = (u2 + v2)1/2.
2.2 Highpass Filtering
Image sharpening can be achieved in the frequency domain by a highpass filtering process, which
attenuates the low-frequency components without disturbing the high-frequency information in the
Fourier transform.
2.2.1 Ideal Filter
A 2-D ideal highpass filter (IHPF) is one whose transfer function satisfies the relation
 0...if ...D(u, v)  D0
H (u, v)  
 1..if ...D(u, v)  D0
------ (Equation 6)
Where D0 is the cutoff distance measured from the origin of the frequency plane.
2.2.2 Butterworth Filter
The transfer function of the Butterworth highpass (BHPF) of order n and with cutoff frequency locus at
a distance D0 from the origin is defined by the relation
H (u.v) 
1
1  D0 / D(u, v)
2n
------- (Equation 7)
Where D(u,v) = (u2 + v2)1/2. A perspective plot and cross section of the BLPF function is shown below.
7
Download