Technique 7.2 Constructing a rule base
9. THE FREQUENCY DOMAIN
9.4 Filtering in the Frequency Domain
One common motive to generate image frequency data is to filter the data. We have already seen how to filter image data via convolutions in the spatial domain. It is also possible and very common to filter in the frequency domain. Convolving two functions in the spatial domain is the same as multiplying their spectra in the frequency domain. The process of
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
filtering in the frequency domain is quite simple:
1. Transform image data to the frequency domain via the FFT 2. Multiply the image's spectrum with some filtering mask
3. Transform the spectrum back to the spatial domain (Figure 9.12)
In the previous section, we saw how to transform the data into and back from the frequency domain. We now need to create a filter mask.
The two methods of creating a filter mask are to transform a convolution mask from the spatial domain to the frequency domain or to calculate a mask within the frequency domain.
Figure 9.12 How images are filtered in the frequency domains.
(This picture is taken from Figure 7.14, Chapter 7, [2]).
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
In Chapter 3, many convolution masks for different functions such as high and low pass filters was presented. These masks can be transformed into filter masks by performing FFTs on them. Simply center the convolution mask in the center of the image and zero pad out to the edge. Transform the mask into the frequency domain. The mask spectrum can then be multiplied by the image spectrum. A complex multiplication is required to take into account both the real and imaginary parts of the spectrum. The resulting spectrum, data will then undergo an inverse FFT. That will yield the same results as convolving the image by that mask in the spatial domain. This method is typically used when dealing with large masks.
There are many types of filters but most are a derivation or combination of four basic types:
low pass, high pass, bandpass, and bandstop or notch filter. The bandpass and bandstop filters can be created by proper subtraction and addition of the frequency responses of the low pass and high pass filter.
Figure 9.13 shows the frequency response of these filters. The low pass filter passes low frequencies while attenuating the higher frequencies. High pass filters attenuate the low frequencies and pass higher frequencies. Bandpass filters allow a specific band of frequencies to pass unaltered. Bandstop filters attenuate only a specific band of frequencies.
To better understand the effects of these filters, imagine multiplying the function's spectral response by the filter's spectral response. Figure 9.14 illustrates the effects these filters have on a 1 -dimensional sine wave that is increasing in frequency.
There is one problem with the filters shown in Figure 9.13. They are ideal filters. The vertical edges and sharp corners are non-realizable in the physical world. Although we can emulate these filter masks with a computer, side effects such as blurring and ringing become apparent.
Figure 9.15 shows an example of an image properly filtered and filtered with an ideal filter.
Notice the ringing in the region at the top of the cow's back in Figure 9.15(c).
Figure 9.13 Frequency response of 1-dimensional low pass, band pass and band stop filters.
Because of the problems that arise from filtering with ideal filters, much study has gone into filter design. There are many families of filters with various advantages and disadvantages.
A common filter known for its smooth frequency response is the Butterworth filter. The low pass Butterworth filter of order n can be calculated as
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
n
D v u D v
u
H 2
0
) , 1 (
) 1 , (
+
=
where
(
2 2)
) ,
(u v u v
D = +
Figure 9.14 (a) Original image; (b) Image properly low pass filtered;
(c) low pass filtered with ideal filter.
(This picture is taken from Figure 7.17, Chapter 7, [2]).
Do is the distance from the origin known as the cutoff frequency. As n gets larger, the vertical edge of the frequency response (known as rolloff), gets steeper. This can be seen in the frequency response plots shown in Figure 9.15.
Figure 9.15 Low pass Butterworth response for n=1.4 and 16
The magnitude of the filter frequency response ranges from 0 to 1.0. The region where the response is 1.0 is called the pass band. The frequencies in this region are multiplied by 1.0 and therefore pass unaffected. The region where the frequency response is 0 is called the stop band, frequencies in this range are multiplied by 0 and effectively stopped. The regions in between the pass and stop bands will get attenuated. At the cutoff frequency, the value of the frequency response is 0.5. This is the definition of the cutoff frequency used in filter design.
Knowing the frequency of unwanted data in your image helps you determine the cutoff frequency
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
The equation for a Butterworth high pass filter (Figures 9.16 and 9.17) is
n
Figure 9.16 High pass Butterworth response for n=1, 4 and 16.
The equation for a Butterworth bandstop filter is
n
The bandpass filter can be created by calculating the mask for the stop band filter and then subtracting it from 1. When creating your filter mask, remember that the spectrum data will be unordered. If you calculate your mask data assuming (0,0) is at the center of the image, the mask will need to be shifted by half the image width and half the image height.
Figure 9.17 Effect of second order (n=2) Butterworth filter: (a) Original image (512 x 512);
(b) high pass filtered D0=64; (c) high pass filtered D0=128; (d) high pass filtered D0=192.
(This picture is taken from Figure 7.21, Chapter 7, [2]).
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm