Gaussian smoothing Gaussian fuzzy Gaussian filter (Gaussian smoothing, Gaussian Blur, Gaussian Filter) C + + implementation

Source: Internet
Author: User



Developed to the current smoothing algorithm, I have no idea how to name this article, had to list some keywords to facilitate the search.

Before we mentioned the mean filter, which means that the color of a pixel is determined by the pixel average of the nine Gongge at its center. On this basis, it developed into a weighted average filter, where the Gaussian smoothing or filter is such a weighted average filter. So how are these weights distributed? Let's take a look at some classic template examples:

Trying to use these filters to manipulate our original diagram, we get a set of results:

Original:

3x3 Gauss:

5x5 Gauss:

Purely from the effect, two templates have played a smooth effect, but the extent of the difference between the shades. So, theoretically, why does it work smoothly? Obviously, the color of the pixel is determined not only by itself, but also by the weighted pixels around it, objectively reducing the difference between the pixels and the surrounding pixels. At the same time, these weights are set up to meet the more recent weight of the law. Theoretically, the distribution of these weights satisfies the famous so-called Gaussian distribution:

This is the formula for 1-dimensional computing.

This is the formula for 2-dimensional computing.

X, y represents the distance from the current point to the corresponding point, and those specific templates are computed by some exceptions in the formula. What needs to be said is that there are not only such exceptions, but it's easy to find complex templates from Wikipedia such as:

Sample Gaussian Matrix

This was a sample matrix, produced by sampling the Gaussian filter kernel (withσ= 0.84089642) at the midpoints of each pi Xel and then normalising. Note that the center element (at [4, 4]) had the largest value, decreasing symmetrically as distance from the center Incre ASEs.

0.00000067 0.00002292 0.00019117 0.00038771 0.00019117 0.00002292 0.00000067
0.00002292 0.00078633 0.00655965 0.01330373 0.00655965 0.00078633 0.00002292
0.00019117 0.00655965 0.05472157 0.11098164 0.05472157 0.00655965 0.00019117
0.00038771 0.01330373 0.11098164 0.22508352 0.11098164 0.01330373 0.00038771
0.00019117 0.00655965 0.05472157 0.11098164 0.05472157 0.00655965 0.00019117
0.00002292 0.00078633 0.00655965 0.01330373 0.00655965 0.00078633 0.00002292
0.00000067 0.00002292 0.00019117 0.00038771 0.00019117 0.00002292 0.00000067

If you see the head is big:)  But it doesn't matter, for the general application, the previous example has been able to complete the task. Code, we still give a 5x5 example:

/**** method to remove noise from the corrupted image by Gaussian filter value* @param corrupted input grayscale binary AR Ray with corrupted info* @param smooth output data for smooth result, the memory need to be allocated outside of the FUNCT ion* @param width width of the input grayscale image* @param height height of the input grayscale image*/void gaussianfilt Er2 (unsigned char* corrupted, unsigned char* smooth, int width, int height) {int templates[25] = {1, 4, 7, 4, 1,   4, 1 6, 4, 7, 4, 4, 1, 4,   7,   };memcpy (smooth, corrupted, width*height*siz, +, +, 7) EOF (unsigned char)); for (int j=2;j
Incidentally, it is obvious that, like the mean filter, this filter does not eliminate the function of the calibration noise.

Gaussian smoothing Gaussian fuzzy Gaussian filter (Gaussian smoothing, Gaussian Blur, Gaussian Filter) C + + implementation

Related Article

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.