Gaussian filter opencv implementation

Source: Internet
Author: User

Learning Task breakdown:

Task:

1. Learn to open an image with opencv
2. Learn how to use opencv to perform Gaussian filtering, see what the Gaussian filtering effect is, and learn the theory of Gaussian filtering.
3. Find a C Language Program for Gaussian filtering, and combine it with the theory of Gaussian filtering.

Gaussian filter:

Gaussian filter is a linear smoothing filter that is suitable for eliminating Gaussian noise and is widely used in image processing noise reduction. In layman's terms, Gaussian filtering is a process of weighted average for the entire image. The value of each pixel is obtained by the weighted average of its own and other pixel values in the neighborhood. The specific operation of Gaussian filter is to use a template (or convolution or mask) to scan each pixel in the image, use the weighted average gray value of pixels in the neighborhood determined by the template to replace the value of the central pixel in the template. 3*3 templates 5*5 templates

G (x, y) = {f (x-1, Y-1) + f (x-1, Y + 1) + f (x + 1, Y-1) + f (x + 1, Y + 1) + [F (x-1, Y) + f (x, Y-1) + f (x + 1, Y) + f (x, y + 1)] * 2 + f (x, y) * 4}/16;
F (x, y) is the gray value of the (x, y) Point in the image, and g (x, y) is the value of the vertex after Gaussian filtering.

Opencv implementation:

# Include "stdafx. H "# include" highgui. H "# include" CV. H "// Gaussian filter function, cvsmooth void gaussianfilter (uchar * data, int width, int height) can be used in opencv {int I, j, index, sum; int templates [9] = {1, 2, 1, 2, 4, 2, 1, 2, 1 }; // template value sum = height * width * sizeof (uchar); // size of memory occupied by the image uchar * tmpdata = (uchar *) malloc (SUM ); memcpy (char *) tmpdata, (char *) data, sum); for (I = 1; I 

 

Comparison of results:

 

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.