# Filters (Frequency)

Frequency filters process an image in the frequency domain. The image is first, Fourier transformed, then multiplied with the filter function, and then transformed back to the spatial domain. Attenuating high frequencies results in a smoother image in the spatial domain, attenuating low frequencies enhances the edges.

## Contents

### Background

Frequency filtering is based on the Fourier Transform. The operator usually takes an image and a filter function in the Fourier domain. This image is then multiplied with the filter function in a pixel-by-pixel fashion:

Equation 1

G(k,l)=F(k,l)*H(k,l)

Where F(k,l) is the input image in the Fourier domain, H(k,l) is the filter function and G(k,l) is the result filtered image.

The form of the filter function determines the effects of the operator. There are basically four different kinds of filters: lowpass, highpass, bandpass and bandstop filters.

A low-pass filter attenuates high frequencies and retains low frequencies unchanged. The result in the spatial domain is equivalent to that of a smoothing filter; as the blocked high frequencies correspond to sharp intensity changes, i.e. to the fine-scale details and noise in the spatial domain image.

A highpass filter yields edge enhancement or edge detection in the spatial domain, because edges contain mostly high frequencies. In other hand, areas of rather constant gray level consist of mainly low frequencies and are, therefore, suppressed.

A bandpass filter attenuates very low and very high frequencies, but retains a middle range band of frequencies. Bandpass filtering is used to enhance edges (suppressing low frequencies) while reducing the noise at the same time (attenuating high frequencies).

The most simple lowpass filter is the ideal lowpass. It suppresses all frequencies higher than the cut-off frequency F0 and leaves smaller frequencies unchanged, which can be described as:

Equation 2

H(k,l)=1 if (k2 l2)1/2 < F0

and

Equation 3

H(k,l)=0 if (k2 l2)1/2 > F0

Where, H(k,l) is the filter function.

In most implementations, F0 is given as a fraction of the highest frequency represented in the Fourier domain image.

The drawback of this filter function is a ringing effect that occurs along the edges of the filtered spatial domain image. See Figure 1.

</div>

Better results can be achieved with a Gaussian shaped filter function.

Equation 4

H(k.l)=exp(-F2(k,l)/2Fo2)

Where, H(k,l) is the Gaussian lowpass filter function, and F0 is the cut-off frequency.

The advantage is that the Gaussian has the same shape in the spatial and Fourier domains and therefore does not incur the ringing effect in the spatial domain of the filtered image. See also Volume 2 Algorithms, "Gaussian filter". See Figure 2.

</div>

A commonly used discrete approximation to the Gaussian is the Butterworth filter. Applying this filter in the frequency domain shows a similar result to the Gaussian smoothing in the spatial domain. One difference is that the computational cost of the spatial filter increases with the size of the filter kernel, whereas the costs for a frequency filter are independent on the filter function. Hence, the spatial Gaussian filter is more appropriate for narrow lowpass filtering, while the Butterworth filter is a better implementation for wide lowpass filtering. See also "Gaussian and Butterworth filters" .

The same principles apply to highpass filters. A highpass filter function can be obtained by inverting the corresponding lowpass filter, e.g. an ideal highpass filter blocks all frequencies smaller than F0 and leaves the others unchanged.

A bandpass filter is a combination of both lowpass and highpass filters. It attenuates all frequencies smaller than a frequency Fmin and higher than a frequency Fmax, while the frequencies between the two cut-offs remain in the resulting output image.

A bandstop filter is a filter that passes most frequencies unaltered, but attenuates those in a specific range to very low levels.

#### Windowed Finite Impulse Response

Window functions are time limited. This means there is always a finite integer Nw such that w(n) almost equal to 0 for all |n|> Nw. The final windowed impulse response is thus always time-limited, as needed for practical implementation. This window method designs a finite-impulse-response (FIR) digital filter based on the Hamming function.

Hamming function can be described as

Equation 5

w(n)=0.53836-0.46164*cos(2Pi*n/N-1)

The method consists of simply windowing a theoretically ideal filter impulse response h(n) by some suitably chosen window function w(n), yielding the following equation:

Equation 6

hw(n)=w(n)*h(n), where n belongs to Z

For example, the impulse response of the ideal lowpass filter is the sinc function.

Equation 7

h(n)=B*sinc(Bn) almost equal to B*(sin(Pi*Bn)/Pi*Bn), where n belongs to Z

where B=2fc is the normalized bandwidth of the lowpass filter and fc denotes the cut-off frequency.

Since h(n)=sinc(BnT) decays away from time 0 as 1/n, the method truncates it to the interval [-N, N] for some sufficiently large N defined by the user and as a result it obtains a finite response filter that approximates the ideal filter.

As for Hamming function, |N| >3 is sufficient for good approximation.

Outline of the method

The Filters Frequency method processes images by filtering in the frequency domain in three steps:

1. It performs a forward Fast Fourier Transform (FFT) to convert a spatial image into its frequency image.
1. It enhances some frequency components of the image and attenuates other frequency components of the image by using a lowpass, highpass, bandpass, or bandstop filter. Frequency filters may be constructed with 1 of 3 methods: Hamming windows, Gaussian filters, and Butterworth filters. However, for the Gaussian filters only lowpass and highpass filters are available.
1. It performs an inverse FFT to convert from the frequency domain back into the spatial domain.

This method performs all three steps in a single combined process.

Note: Since the core algorithm of this module is the FFT, it requires that all the dimensions of an N-dimensional dataset were powers of two. To be able to use this algorithm on datasets with arbitrary dimensions, the data is zero padded to powers of two before applying the forward FFT and stripped down to the original dimensions after applying the inverse FFT. The powers of two are not kept identical because symmetrical Fourier pictures are not required.

The module also creates a Gabor filter, which is essentially a tilted Gaussian with two unequal axes at an offset (freqU, freqV) from the origin. A Gabor filter only responds to a texture having both a particular frequency and a particular orientation. Note that a filter and its mirror image reflected across the u and v frequency axes produce identical frequency responses. See also Volume 2 Algorithms, "Gabor Filter".

The Frequency Filter algorithm also used in homomorphic filtering, for more information refer to Volume 2 Algorithms, "Homomorphic Filter".

#### References

Digital Image Processing Second Edition by Rafael C. Gonzalez and Richard E. Woods, Prentice-Hall, Inc., 2002, Chapter 4.5, pp. 191-194.

#### Image types

2D and 3D grayscale images.

### Applying the Frequency Filter algorithm

To run this algorithm, complete the following steps:

1. Open an image of interest.
2. Select Algorithms > Filters Frequency.
3. The Frequency Filter dialog box appears.
4. Fill out the dialog box.
5. Specify the destination image frame, and then, press OK.

Depending on whether you selected the New Image or Replace Image option, the result appears in a new window or replaces the original image.

 Process each slice independently (2.5D) If true, processes each slice of a 3D image independently. Windowed finite impulse response If selected, the method will use the Windowed finite impulse response algorithm. Crop image to save memory If selected, this option crops image if the (largest image dimension kDim - 1) value exceeds the smallest power of 2 number which is more or equal to the largest dimension. Convolution kernel diameter-odd It must be an odd integer larger or equal than 3, see also [FiltersFrequency.html#wp1056083 "Windowed Finite Impulse Response"]. Gaussian filter If selected the method uses the Gaussian filter. Butterworth filter If selected the method uses the Butterworth filter. Order The order of the Butterworth filter. Destination New image The result image appears in a new image frame Replace image The result image appears in the same image frame, replacing the result image. Filter specifications In that part of the dialog box, first select the filter type. Choose among: Lowpass, Highpass, Bandpass and Bandstop option. Then. Enter the lowpass frequency value, and also the higher frequency cutoff value if the Bandpass option is chosen. OK Applies the algorithm according to the specifications in this dialog box. Cancel Disregards any changes that you made in the dialog box and closes this dialog box. Help Displays online help for this dialog box.