The image denoising smoothing Gaussian filter

  Linear Gaussian filter is selected smoothing filter weights according to a Gaussian function, have good filtering effect of noise and normally distributed random distribution. It can assist most of the edge detection algorithm,

Grayscale image is expanded edge (edge ​​thickness becomes large), so that the noise point is reduced, thereby reducing the number of edge detection noise.

  Two-dimensional Gaussian formula is as follows:            

  

  Wherein σ is the standard deviation of the normal distribution, the value of which determines the variation width of the Gaussian function, the corresponding filter weight is the value. Gaussian distribution with the two-dimensional filter of common templates as follows:

           

  Generating a template, as is the center of the matrix (0,0) are then substituted into the formula, to obtain a matrix type decimal, the upper left corner of the matrix elements of its reciprocal is multiplied by K, with a value of 1,

Other locations of matrix elements are also multiplied by K, then the matrix into an integer. Whereby you can obtain a template, which is a square matrix odd ranks length, determined by the value of σ. The larger σ, the matrix from the inside

More to the outside gradient. Generally, σ 3 * 3 template according to the above formulas calculated = σ 0.85,5 * 5 template = σ 1.4,7 * 7 = 1.72 template. General According to a particular image, the selection of the appropriate formwork

Small (blur radius) and standard deviation (weight), for example, closely spaced edges should use a small target template, if the degree of filtering is not enough, the value of [sigma] can take a large slightly; if the target was massive distribution, surface noise

You can use a large plot template large, but the overall image becomes blurry.

  Gaussian convolved image template: Template Gaussian convolution is separable (matrix rank = 1), and therefore when the size n * n deconvolution m * m image size, complexity from n- 2 * m 2 reduced to m * 2N 2 . This means

In the same real-time requirements, you can use more blur radius. The so-called separable, refers to split into n * n matrix of two convolution twice a size of a row vector and a column vector of n, the image, the result of the convolution

And a convolution same.

  The following example shows a Gaussian blur:

  

  

  Matlab implementation of the Gaussian filter are the following code:

  

% Gaussian filter template generation
function template=gaussiantemplate(sigma,size)
    %sigma=0.85 size=3;
    %sigma=1.4 size=5;
    %sigma=1.72 size=7
    syms x y;
    gaussian=(1/(2*pi*sigma^2))*exp((-(x^2+y^2)/(2*sigma^2)));
    template=zeros(size,size);%奇数个
    for i=1:size
        for j=1:size
            template(i,j)=double(subs(gaussian,[x,y],[i-(size+1)/2,j-(size+1)/2]));
        end
    end
    
    k=1/template(1,1);
    for i=1:size
        for j=1:size
            template(i,j)=uint8(template(i,j)*k);
        end
    end
    
    
end  
%高斯滤波
function gaussian=gaussianfilter(grayimg,sigma,size)
    operator=gaussiantemplate(sigma,size);
    gaussian = filter2(operator,grayimg);
    gaussian = uint8(gaussian./sum(sum(operator)));
end

 

 

 

                               

  

 

Guess you like

Origin www.cnblogs.com/kensporger/p/11628050.html