Gaussian image filtering principle and its programming discretization Implementation Method

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_640577ed0100yz8v.html

1. Image Filtering

In the field of 3D computer vision, feature extraction for two-dimensional images is usually the first key step, including extracting the edges, corners, and textures on two-dimensional images. We can extract the following features from these components:

1) gray-scale hops brought about by edge imaging of different objects;

2) the border between different materials or different color components of an object will produce a gray-scale hop;

3) The contour of an object has different reflection characteristics from the background, and the gray-scale value is not continuous;

4) when an object is illuminated, it forms a shadow, which also forms a gray-scale hop.

From the above analysis, we can see that if we can better extract the information from two-dimensional images, it can be of great support for post-goal functions such as 3D reconstruction, object positioning, and space monitoring. These features, such as points, lines, and surfaces that contain the image contour and spatial location information, are displayed as discontinuous or drastic changes in the gray value. That is to say, if we can find the point position of the gray level discontinuous according to the gray level matrix of the image, then feature extraction is realized.

If we want to find its discontinuous point from the one-dimensional signal, we can evaluate the signal according to the content of advanced mathematics, the local maximum value of the first derivative is the point where the signal changes dramatically.

In a two-dimensional function, the gradient vector represents the direction of the maximum change rate of the function. Therefore, for two-dimensional signals, the gradient vector model can be used to select non-continuous points of the gray value. In this way, we can use the discretization gradient approximation function to detect the gray-scale hop location of the gray matrix of the image, so as to achieve feature extraction.

In reality, images obtained by cameras often have noise, and the signal does not have an ideal step distortion. In this way, if the Laplace operator is still directly used for gray-scale hop detection, this will generate many false features. Therefore, before image processing, grayscale images must be filtered.

2. Gaussian filtering principle

Gaussian filtering is the most commonly used method for image filtering. In this paper, We need to mine and sort out the idea of this filtering and the specific programming implementation principles.

2.1 Summary of Noise Characteristics

Generally, the purpose of an information processing system is to extract real and useful information from the measured noisy signal, which is often unknown, therefore, information estimation can only be performed through filtering.

When we perform mathematical simulation or error evaluation, we often think that the noise introduced by the sensor follows a normal distribution (Gaussian white noise ), in this way, we can design filters in a targeted manner.

2.2 popular filtering Comprehension

Filtering is a probability theory and method for estimating another random process based on the results of observing a random process. More broadly speaking, filtering is a mathematical model established to convert the image data for energy, while low energy is eliminated. noise is a low energy part.

The data obtained from the sensor is usually discrete, and the common image filtering methods are based on the gray-scale values of the neighboring pixels of the pixel for the corresponding weighted average (after actual test, through this way, this can effectively eliminate noise signals that are similar to white noise. For image filtering, this will make the image edge a bit more blurred than before filtering ), different filtering methods have different weights and different weighted data ranges.

2.3 Gaussian filter

The Gaussian filter function is introduced as follows:

 

The curve of this function is a straw hat-like symmetric graph. the integral of this curve for the entire covered area is 1. The idea of Gaussian filter is to discretization the Gaussian function and take the Gaussian function value on the discrete point as the weight value, the gaussian noise can be effectively eliminated by weighted average of each pixel in the gray matrix we have acquired within a certain range of neighborhoods.

3. Gaussian filter discretizationAlgorithmImplementation

We can find that many textbooks and online materials describe the principle of Gaussian filtering by using Gaussian operators to perform convolution operations on images. In fact, in various algorithm libraries, such as MATLAB and opencv, a matrix template is used for weighting, taking the eight connected areas of the image for example, the pixel value of the intermediate point is equal to the average value of the pixel value in the eight-connected zone, so as to achieve smooth effect. This template is often used as a Gaussian Kernel.

According to the above analysis, Gaussian Kernel is the key to the entire solution. Obviously, it is calculated by using a two-dimensional Gaussian function. The formula for calculating the discrete Gaussian Kernel matrix is given here.

Discrete Gaussian convolution kernel H: (2 k + 1) × (2 k + 1) dimension. The element calculation method is as follows:


Sigma is the variance, and K determines the dimension of the kernel matrix. The two values are analyzed below.

4. Comparison with Matlab function running results

The Matrix Algorithm of Gaussian convolution kernel is verified here.

1) use the following in MATLAB:CodeA 3 × 3 core can be generated.

Filter = fspecial ('gaussian ', 3, 1 );

The resulting kernel matrix is:

Filter =

0.0751 0.1238 0.0751

0.1238 0.2042 0.1238

0.0751 0.1238 0.0751

2) for the above formula, we can obtain the Gaussian convolution kernel of 3 × 3 using k = 1, Sigma = 1:

As mentioned above, we conduct weighted filtering. The sum of the weights must be 1, and the Gaussian filter kernel function obtained above must also be normalized:

This proves the correctness of the kernel function calculation method.

5. usage of the cvsmooth function in opencv

The function is prototype:

Void cvsmooth (const cvarr * SRC, cvarr * DST,

Int smoothtype = cv_gaussian,

Int param1 = 3, int param2 = 0, double param3 = 0, double param4 = 0 );

The first three parameters of the function are easy to understand. The last four parameters are analyzed below.

1) if param1 and param2 are specified, they represent the columns of the kernel function, that is, the width and height of the filter window;

2) param3: sigma value of Gaussian convolution

3) If you want to use an asymmetric Gaussian Kernel, param4 is introduced. The last two parameters represent the horizontal kernel and the vertical kernel dimension respectively;

4) if param3 is not given, the first two parameters param1 and param2 calculate Sigma. Here, it is based on the characteristics of Gaussian distribution (the probability of numerical values distributed in (μ-3 σ, μ + 3 σ) is 0.9974). If the kernel matrix is larger, the corresponding Sigma is larger. On the contrary, if Sigma is larger, the coverage of the core matrix is larger. Specific to opencv, use the following formula for calculation (according to itsSource codeDisplay ).

5) according to this formula, if param1 and param2 are 0 (or not given), then the size of the filter window is determined by Sigma represented by the last two parameters.

6. Summary

This article mainly summarizes my experiences in the last few days, including my understanding of filtering, the principles of Gaussian filtering, and a glimpse of the implementation process. At the same time, the functions implemented by filtering using opencv are also explained accordingly. When selecting Sigma, you should note that if the selected Sigma is too large, the filtering degree will be deepened, which will lead to blurred image edge, which is not conducive to the next edge detection. If it is too small, the filtering effect is not good. I do not have a good understanding of the selection of this parameter. I hope you can discuss the progress together.

 

References:

[1] http://zh.wikipedia.org/wiki/normal Distribution

[2] http://www.opencv.org.cn/index.php/cvimage Processing

[3] http://www.cnblogs.com/donj/articles/1656122.html

[4] Learning opencv Chinese Version

[5] Computer Vision (MA songde Edition))

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.