Spatial domain smoothing filter

Original: https: //www.cnblogs.com/zfyouxi/p/5144068.html

1. enhanced spatial domain

(1) Template operation

Image processing. Template can be seen as the n * n (n is an odd number usually) form. Continuously moving the entire stencil image, the stencil to form a pixel range processing accordingly.

Template operations are divided into:

  • Template convolution
  • Sort template

Template convolution is the gradation value of the gradation values corresponding template within the template and the multiplied pixel, averaging the current center pixel is assigned to the form template. As its gray value;

Template sorting is to sort the template pixel gray value, whichever order statistics as a template a center pixel gray value.

Matlab to do very efficient convolution template, templates inside out and die sub-matrix multiplication averaging copyright emphasis on it

We are very easy template think the central point is a special case of the border. There are very many border processing practices:

  • Ignore border
  • Extrapolation boundary
  • Change the template field

Ignore the border is the template directly in the non-boundary movement operating point, ignore these boundary points. The advantage of course is done with high efficiency, more suitable for larger or people interested in the case where an edge portion of the image is not the image size;

Extrapolated boundary pixel portion missing when filled by definition is a template center point as a boundary, edge pixels can be given up and make certain tone value calculation. Advantage that, without sacrificing performance, to a process boundary. But up edge pixel gray value setting inevitably lead to discontinuities of the boundary pixels, in severe cases, cause distortion;

FIELD template change means change the size of the template in the form of a boundary process, the boundary special treatment, such as 3*3stencil considering only the points of the image at the upper left corner pixel processing 2*2stencil operations. Special considerations such as borders neither distortion nor ignore whatever pixels. But when extrapolating the border is bound to have some overhead. Slightly affect the performance of image processing (Points can write, to make up for the overhead inferred brought at the expense of program complexity).

Whatever the boundary process is not perfect, it is assigned to a certain extent, once again re-mold copyright.

(2) the spatial domain filtering

The enhanced spatial domain technique called template image is used in computing the spatial domain filtering. Based on the spatial frequency domain filter into the filter smoothing filtering (removal and attenuate high frequency components) and the sharpening filter (and attenuate low frequency components removed), calculated based on the characteristics of the filter is divided into linear filtering and nonlinear filtering .

Thus the spatial domain filtering can be divided into:

classification Linear Nonlinear
smooth Linear smoothing Non-linear smoothing
Sharpen Linear sharpening Nonlinear sharpening

2. Mean Filter

(1) mean filter

FIELD mean filter is by definition the stencil averaging pixel gradation. It is the classical linear smoothing filter. Spatial filtering is often used to remove additive noise filtering algorithm usually referred to as a filter module package.

Mean filter template is ones(n, n), all the elements within the template is one, that is, they are exactly the same weight.

 

Other commonly used linear filtering are:

  • Weighted filtering : the central element generally larger weight, and symmetrically outwardly decreasing
  • Gaussian filter : weighting filtering special case, the template is determined based on a Gaussian distribution coefficient

(2) code implementation

First call Matlab function to the image by adding 3% of the salt and pepper noise :

salt = imnoise(original,'salt & pepper',0.03);

The next structure we mean filter. I used to change the template fields . That is to be inferred boundary conditions do special treatment:

function [ filtered ] = MeanFilter( noise ) filtered = noise; h = size(filtered, 1); w = size(filtered, 2); for i = 1 : h for j = 1 : w up = max(i - 1, 1); down = min(i + 1, h); left = max(j - 1, 1); right = min(j + 1, w); filtered(i, j) = mean(mean(noise(up : down, left : right))); end end end

Here I call a series maxand minfunction to avoid to write more complicated if statement. After determining the stencil directly call boundary meanconcept averaging function, dilute stencil convolution (rear edge detection will be done explicitly stencil convolution).

3. The median filter

(1) median filter

Median filtering the selected template median pixel gray value is assigned to the center pixel template, a classic non-linear smoothing filter.

Ideally, the salt and pepper noise removal effect superior median filter mean filter. Is isolated because it can effectively eliminate the step pulse noise. The comparative analysis later.

2-D median filtering can also select a variety of templates, I'm here to select the most simple 8-field template to do presentations.

(2) code implementation

I detect the same border. Special treatment:

function [ filtered ] = MedianFilter( noise )
    filtered = noise;

    h = size(filtered, 1);
    w = size(filtered, 2);

    for i = 1 : h
        for j = 1 : w up = max(i - 1, 1); down = min(i + 1, h); left = max(j - 1, 1); right = min(j + 1, w); sub = noise(up : down, left : right); sub = sub(:); filtered(i, j) = median(sub); end end end

The sub-matrices need only turn into a vector. And then seek medianto be.

Note: I did meticulous research Matlab median function implementation, if it is an order of magnitude square algorithm, then we have to optimize the following two ways to increase the speed of the median filter:

  • Seek more efficient order statistics algorithms. See Introduction to Algorithms - expectations for the linear-time algorithm selection and worst-case linear-time algorithm for the selection of
  • Template using the continuity of movement. Movement region adjacent small number of pixels only different points, can be constructed according to the nature of the template incremental order statistics of linear time algorithm

4. The results of the control discussed two filters

(1) The results are shown smoothing

The following is the removal of salt and pepper noise, the median filter is more effective in:

Write pictures at description here

The following is a Gaussian noise removal, mean better filtering effect:

Write pictures at description here

(2) discussion

Here there is no mathematical analysis and mathematical theory. It did not give examples. Only a brief analysis of the visual comprehension of:

  1. Median filtering better removal of salt and pepper. Since step pulse pepper noise is noise (or value 0 and smaller probability 255), the median filter to the median is, the step value is not affected, it can almost completely filter out step pulse noise.

     

    And assigning a weight average filtering process is not changed when the step value. Then an error value is generated by the impact on the step during averaging greater. So the effect is not ideal.

  2. Is the Gaussian noise in the image of each pixel from the original tone value are distributed according to a Gaussian random noise do. So on behalf of significance in the selected value is not large, because each pixel is independent and identically distributed. Median filter corresponds to the template in the re-elected through a gray value, and the filtering effect of image noise is Gaussian noise no significant improvement in conversion, the comparator mean filter under better.

Guess you like

Origin www.cnblogs.com/Ph-one/p/11568406.html