Photoshop algorithm implementation Advanced-blur filter-Gaussian filter (23)

Source: Internet
Author: User

Photoshop Algorithm Implementation Advanced-blur filter-Gaussian filter (23)

[Email protected]

Http://blog.csdn.net/kezunhai

Gaussian Blur (Gaus Blur) uses a two-Gaussian template to blur the image, which is used for image blurring (removal of detail and noise), and its processing effect gives a better feeling of softness.

One Gaussian:


Ivigos:



Theoretically, Gaussian distributions have non-negative values on all domain definitions, which requires an infinitely large convolution core. In fact, you only need to take the value of 3 times times the standard deviation around the mean value, and remove it directly from the external part. As a standard deviation of 1.0 integer value of the Gaussian core:


In some cases, the following modules can be used to approximate the Gaussian core:


Based on the kernel size and variance of the user input, the Gaussian kernel is computed and Gaussian filter is realized, and the Gaussian kernel creation algorithm is as follows:

Create a Gaussian core///ksize: The size of the convolution core 3, 5, 7, etc. (3x3, 5x5, 7x7)/sigma: Variance void Photoshop::creategausskernel (float **pdkernel, int ksize, float sigma) {float DDIs;  A point in the array to the center point distance float dcenter = (kSize-1)/2;float dSum = 0;  Float Dvalue;int I, J; Generate Gaussian data for  (i=0; i<ksize; i++) {for (j=0; j<ksize; J + +) {DDIs = FABSF (i-dcenter) + FABSF (j-dcenter);  Dvalue = exp (-ddis*ddis/(2*sigma*sigma+dbl_epsilon));pd kernel[i][j] = Dvalue with sum to approximate square sum;  Dsum+=dvalue; }}//Normalization for  (i=0; i<ksize; i++) {for (j=0; j<ksize; J + +) {Pdkernel[i][j]/= (Dsum+dbl_epsilon);}}  
Gaussian filter algorithm:

void PhotoShop :: Gaussianblur (Cv::mat &img, Cv::mat &dst, int ksize, float sigma) {int height = img.rows;int width = img.cols;int Chns = Img.channels (); int I, J, K,p, q;//allocate Gaussian kernel space float **pkernel = new Float*[ksize];for (i=0; i<ksize; i++) {pkernel[i ] = new Float[ksize]; ZeroMemory (Pkernel[i], ksize*sizeof (float));}  Creategausskernel (Pkernel, Ksize, Sigma); Create a Gaussian kernel if (Dst.empty ()) dst.create (height, width, img.type ()), float sum = 0;int border = (kSize-1)/2;for (i =border; i&l T;height-border; i++) {unsigned char* dstdata = (unsigned char*) Dst.data + dst.step*i;for (j=border; j<width-border; J + +) {for (k=0; K&L T;chns; k++) {sum = 0;for (p =-border; p<=border; p++) {for (q =-border; q<=border; q++) {sum + = GetPixel (img, i+p, j+q, K) *pkernel[p+border][q+border];}} Dstdata[j*chns+k] = saturate_cast<uchar> (sum+0.5);} For-k}}//For i} 
Algorithm test:


Gaussian filter has been widely used in many algorithms because of its linearity and good denoising effect, such as the Gaussian filter used in preprocessing of canny operator, and the implementation of Sobel operator in OpenCV is also used as preprocessing step, It's still famous. The SIFT operator uses Gaussian pyramid and Gaussian difference to extract candidate feature points, and interested friends can further understand the application of Gaussian filtering.

Kezunhai Source:Http://blog.csdn.net/kezunhai Welcome to reprint or share, but be sure to declare the source of the article.

Photoshop algorithm implementation Advanced-blur filter-Gaussian filter (23)

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.