Some understanding of Gaussian filtering

     Introduction to Filtering Algorithms

         In image processing, the commonly used filtering algorithms are mean filter, median filter and Gaussian filter. Mean filtering uses the average value of all pixels in the template to replace the gray value of the central pixel of the template. This method is prone to noise interference and cannot completely eliminate noise, but can only relatively weaken the noise; median filtering calculates the median of all pixels in the template. value, and use the calculated median volume to change the gray value of the central pixel of the template. This method is not so sensitive to noise and can better eliminate salt and pepper noise, but it is easy to cause image discontinuity. When the Gaussian filter smoothes the pixels in the image neighborhood, the pixels in different positions in the neighborhood are given different weights. While smoothing the image, it can retain more of the overall gray distribution characteristics of the image.

     Gaussian filter

        In numerical image processing, Gaussian filtering can be implemented in two main ways. One is discretized window sliding window convolution, and the other is through Fourier transform. Here I mainly want to talk about the first method of Gaussian filtering. When discretizing the window sliding window convolution, the Gaussian kernel is mainly used, and the Gaussian kernel is generally a Gaussian template with an odd size. Commonly used Gaussian templates have the following forms:

       The above picture shows two commonly used Gaussian templates. The left side is the commonly used 3*3 Gaussian template, and the right side is the commonly used 5*5 Gaussian template. So, how are the parameters in the above Gaussian template obtained? This is a problem that I didn't quite understand when I first came into contact with Gaussian filtering. After a period of study, check the information. I gradually understand how the parameters in the Gaussian template are obtained!

       The parameters in the Gaussian template are calculated by the Gaussian function. When calculating the Gaussian template parameters, use the following formula:

    The square of x and the square of y respectively represent the distance between other pixels in the neighborhood and the central pixel in the neighborhood, and Sigma represents the standard deviation.


    As shown in the figure above, it can be seen from the two-dimensional Gaussian image that the smaller the standard deviation, the narrower the two-dimensional Gaussian image is, and the smoothing effect is not obvious; the larger the standard deviation, the shorter and wider the Gaussian image, and the more obvious the filtering effect. The main code is as follows:

        
        double weight;
	double sum = 0;
	double Sigmma = 1;

	double Gaussian_Temp[SIZE][SIZE] = {0};
	int i,j;

	weight = 2*PI*Sigmma*Sigmma;
	for(i =0;i <SIZE;i++)
	{
		for(j = 0;j < SIZE;j++)
		{
			Gaussian_Temp[i][j] =weight* exp(-((i-SIZE/2)*(i-SIZE/2)+(j-SIZE/2)*(j-SIZE/2))/(2.0*Sigmma*Sigmma));
			sum += Gaussian_Temp[i][j];
		}
	}

	for(i = 0; i < SIZE;i++)
	{
			for(j = 0;j < SIZE;j++)
		{
			Gaussian_Temp[i][j] = Gaussian_Temp[i][j]/sum;//Normalization
			printf("%f ",Gaussian_Temp[i][j]);
		}
			printf("\n");
	}
        Taking the 5*5 Gaussian template as an example, the calculated Gaussian template value is:

        The calculated result is different from the Gaussian template of 5*5 in the above figure. Why is it different? Looking up the information, it is explained that the Gaussian template is actually the feature of simulating the Gaussian function. It has symmetry and the value decreases continuously from the center to the surrounding. The 5*5 template in the above image just meets such characteristics, and it is very simple. It is easy to be accepted by everyone, so it is more classic. That is to say, the 5*5 Gaussian template in the above image is only an approximation of the theoretically calculated value of the two-dimensional Gaussian function. How to obtain the 5*5 Gaussian template in the picture from the theoretically calculated value? This is how I understand the origin of each parameter in the Gaussian template. How to get the value in the Gaussian template from the theoretical value is not very clear! !

      In addition, when calculating the Gaussian template parameters, normalization is required. Why do you need normalization? My understanding is as follows:

      This is a one-dimensional Gaussian function probability density function image. The horizontal axis represents the possible value x, and the vertical axis represents the probability distribution density F(x). From the Gaussian probability density function, it is not difficult to understand that the area of ​​the graph enclosed by such a curve and the x-axis is 1. In practical applications, when calculating the discrete approximation , the pixels outside the distance of about can be regarded as ineffective , and the calculation of these pixels can be ignored. That is to say, in order to simulate the relevant properties of the Gaussian function as much as possible, when calculating the Gaussian template, the sum of each value in the calculated Gaussian template must be 1, which is why normalization is required.

    Another explanation for the normalization of the template calculated by the Gaussian function is that after normalization, the center pixel of the template calculated by convolution is limited to the grayscale range of 0-255. If the gray value of all pixels in a neighborhood is 255, after using the template for convolution, the obtained template center pixel gray value is still 255; if the calculated sum of the Gaussian template parameters is less than 1, then through this After the template is convolved, the gray value of the center pixel of the template will be less than 255, which deviates from the actual gray value and causes errors.

references:

http://lps-683.iteye.com/blog/2251180



 

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325407259&siteId=291194637