[Digital Image processing] spatial filtering

Source: Internet
Author: User
1. Spatial filtering

Spatial filter, is directly in the gray value, do some filtering operation. Filter the word, in fact, from the frequency domain, a certain frequency components to filter out the meaning. Most linear spatial filters (such as mean filters) are performed on some gray-scale values in space, and the linear spatial filter has a one by one correspondence with the frequency domain filter (for example, the mean filter is essentially a low-pass filter), which helps to understand the characteristics of the filter. However, for non-linear filters (such as maximum, minimum, and central value filters), there is no such a one by one-corresponding relationship.

The operation used for linear spatial filtering is convolution, which is calculated as shown below.


We use this operation when we perform spatial filtering.

There are two possible problems with this equation. This is done in the space domain, so there should be no problem with the formula. However, if we switch to the frequency domain, we will find that we use the filter is non-causal, according to my previous in the digital signal processing of the section, the non-causal has 0 phase characteristics, but is not achievable, because the need for future input. In this case, we are dealing with one frame at a time in image processing, so the non-causality is not a problem. And most importantly, the 0 phase feature does not distort the image, which is important.

Another problem is the boundary problem, when the center of the filter is near the edge of the image, part of the filter will be located outside the image, then we usually take the 0 operation to solve. However, in some cases, the direct fill 0 operation will make the image after the Operation Black Edge. Therefore, the common operation is also, ① Select the nearest point fill, ② fill the point is a circular image of the mirror, ③ the original image as a periodic signal to fill.


2. Several typical spatial filters 2.1 Smoothing Filter

Considering the spatial domain, we mean the smoothing filter, which has the mean filter and the weighted average filter.


It is well understood that the points within the filter range are averaged (or weighted average). This will make the image smooth and help remove some noise.

We put it in the frequency domain to consider, in fact, this is a very typical low-pass filter. This filter filters out high-frequency components, so you can make the image smooth. Its frequency response is shown below.


The frequency response of 3x3 average filter


Frequency response of 3x3 weighted average filter

First, for the amplitude characteristics of two filters. The pass band of the average filter is narrower than the weighted average filter, so the image processed with the average filter is more blurred than the image processed by the weighted filter.

Note the phase characteristics of the average filter, whose phase characteristics are not a plane, in some places the value is π. First, the average filter is a even-real function whose frequency response is a real function. However, some of its frequency response is negative, which results in the calculation of angle () of Matlab as π. In fact, it still has 0 phase characteristics.

Use it to deal with the actual processing of the image, you will get the following results.


It's hard to tell what the difference is by looking at the results of their treatment. Therefore, the difference between the weighted average filter and the average filter is easy to understand from the frequency response. This article is just a simple introduction to the mean filter, in detail, see [Digital Image processing] Image denoising Preliminary (1)--mean filter


2.2 Statistical sorting filter

The application of statistical sorting filter is also widely used, and it is a typical nonlinear filter. Mainly includes, the maximum filter, the minimum filter, the central value filter and so on. Here as the representative, mainly said central value filter, central value filter for the removal of salt and pepper noise is particularly effective.

The so-called Central value filter, which is the gray value of the pixels within the filter range, is sorted to select the central value as the gray value of this pixel. The same can be explained by the maximum filter and the minimum value filter.

We add a picture of salt and pepper noise, and then try to remove it with a central value filter.



From the histogram, it can be seen that the central value filter has good denoising effect for salt and pepper noise. For more information on nonlinear filtering, see [Digital Image processing] Image denoising Preliminary (2)--Nonlinear filter


2.3 Sharpening Filter

Using an average filter, the image can be smoothed, essentially averaging the image within the filter range. From the frequency domain, the average filter is a low-pass filter. However, the so-called sharpening, that is, the details of the image is highlighted. Here's a hypothesis, assuming that the detail part is the high-frequency component of the image. From this point of view, the sharpening filter is actually the opposite operation with the average filter.

For a one-time meta-function, the first order is divided into


Such a differential is referred to as a forward differential, and such a differential produces an offset of a sample point (offset by one pixel for the image). In order to avoid such offsets, it is common to use a forward differential with a backward differential, so that there is no offset, as shown below.


Now expand the second phase differential to two-dimensional images, as shown below.


Write it in the form of a filter, as shown in the left. To emphasize its differential effect, we can also add a differential effect in the oblique direction, as shown in the right. We call it the Laplace operator.


Its frequency response is shown below.


Frequency response of Laplace filter in four directions


Frequency response of Laplace filter in eight directions


We can see that the eight-directional Laplace filter has a strong emphasis on high-frequency components. Its low-frequency part has a minimum value of 0, which means that after Laplace filtering, only the high-frequency portion of the image is left (in the space domain, only the marginal part is left). Therefore, if used for image sharpening, the results can be superimposed to the original image, in fact, it is quite with the amplitude of the filter to move up to 1, to ensure that the low-frequency part of the same, emphasizing high-frequency parts.



2.4 High-lift filterHigh-lift filtering is generally used to make the picture clearer. The steps are as follows, first blurring the image, and then removing the blur form from the original.
Thus, the image can be back-sharpened masking, and then superimposed on the original picture, so that the image is clearer.
When k=1, this operation is called anti-sharpening masking.        When k>1, this operation is called high-lift filtering. In fact, high-lift filtering is also a sharpening filter, which emphasizes the edge of the image (or part of the transition). The following experiments can be used to deepen the understanding of high-lift filtering.
The results are actually clearer than the original.         For a deeper understanding, we will draw the gray curve of line 77th to see what the concrete is like. The first is the 77 lines of the original image and 77 lines after the Gaussian blur.
Then there is the difference between the original and the blurred image, and the image is shown below.
As you can see, the edges are highlighted, and below, we multiply this part by a constant and then stack it back to the original image to get the result of a high-lift filter, as shown below.
As you can see, the edge part of the font is emphasized. This will make the font in the sense, more clear.
2.5 Sobel FilterThe Sobel filter is also a common filter.       The principle is similar to the sharpening filter, which uses a first order differential, which allows the edge portion to be retained, filtering out the rest of the smooth part. Now let's analyze the Sobel filter. Looking at this filter vertically, it is a central 2-time micro-operation, which is a high-pass filter. It can be determined that the Sobel filter is able to extract the edges of the image. Look at the longitudinal, the longitudinal is actually a weighted average filter, this also shows that, in fact, the Sobel filter has a certain smoothing effect.                 In conclusion, the Sobel filter is synthesized by the following two filters. The Sobel filter has two directions, so the frequency response in its two directions is shown below.


The Sobel filter extracts the edge portion of the image. Viewed from the frequency domain, it retains the middle band portion of the image.


3. Reference Code

Close a

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.