Filtering#

The operation of filtering consists of applying a convolution with a specific PSF on an image so as to modify the image, or to enhance some features, or to reduce some frequencies.

In this section we will see some examples of filters. First, we begin with common filters (blur, edge detection and sharpening) that are defined from an analysis in the image domain. Then, we continue with two important families of filters: low-pass and high-pass filters, which are defined from considerations in the Fourier domain.

Blur filtering#

An example of blur filtering is given in Fig. 37. Each pixel of the output image is a mean of the pixel intensities in a window in the original image. The PSF in Fig. 37 is very simple:

\[\begin{split} h = \begin{bmatrix} 1 & 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 & 1 \\ \end{bmatrix} \end{split}\]

Other size, shape, and coefficients can be used in the PSF as long as it defines a (possibly weighted) mean.

../_images/blur-filtering.svg

Fig. 37 Blur filtering.#

Edge detection filtering#

Edge detection consists of highlighting the borders of the “objects” in the image. This corresponds to compute the discrete derivatives of a pixel with its four neighbors, so that a specific pixel \((x,y)\) in the output image \(f\) is defined as (\(g\) is the original image):

\[\begin{split} f(x,y) &= g(x,y) - g(x-1,y) \\ &\quad+\; g(x,y) - g(x+1,y) \\ &\quad+\; g(x,y) - g(x,y-1) \\ &\quad+\; g(x,y) - g(x,y+1) \\ &= 4g(x,y) - g(x-1,y) - g(x+1,y) - g(x,y-1) - g(x,y+1) \\ \end{split}\]

Thus the PSF in this case is:

\[\begin{split} h = \begin{bmatrix} 0 & -1 & 0 \\ -1 & 4 & -1 \\ 0 & -1 & 0 \\ \end{bmatrix} \end{split}\]

The result is given in Fig. 38.

../_images/edge-filtering.svg

Fig. 38 Edge filtering.#

Sharp filtering#

Sharp filtering strenghtens the border in the image. Then it can be computed as the sum of the original image with an edge detection. This yields the following PSF and the output given in Fig. 39.

\[\begin{split} h = \begin{bmatrix} 0 & -1 & 0 \\ -1 & 5 & -1 \\ 0 & -1 & 0 \\ \end{bmatrix} \end{split}\]
../_images/sharp-filtering.svg

Fig. 39 Sharp filtering (or sharpening).#

Low-pass filtering#

Because filtering is the convolution of an image with a specific PSF, it can also be achieved by multiplying the DFT of the image and the DFT of the PSF. Then it becomes possible to define the filter in the Fourier domain instead of the spatial domain.

Fig. 40 shows an example of low-pass filtering. The first row shows the filtering as a convolution in the spatial domain, the second row shows the same information in the Fourier domain, where the DFT of the filtered image is the multiplication (point to point) of the DFT of the original image and the PSF.

Low-pass filtering preserves only the low frequencies, yielding a blurred image.

../_images/lowpass-filtering.svg

Fig. 40 Example of low-pass filtering: only the low frequencies are kept. Top row: spatial domain, bottom row: amplitude of the DFT (the phase is not shown for brevity).#

Similarly, the blur filter defined above is also a low-pass filter.

High-pass filtering#

Contrary to low-pass filtering, high-pass filtering preserves only the high frequencies, i.e. the sudden changes in the intensities (Fig. 41).

../_images/highpass-filtering.svg

Fig. 41 Example of high-pass filtering: only the high frequencies are kept. Top row: spatial domain, bottom row: amplitude of the DFT (the phase is not shown for brevity).#

Similarly, the edge detection filter defined above is also a high-pass filter.