Gaussian Blur, see Baidu Encyclopedia.
Convolution is also used to achieve the formula for each convolution element:
Where Bldg is the standard variance, the general value is 1.
The x and y correspond to the integer distance from the current position to the convolution center, respectively.
Because the weights in the Gaussian kernel need to be normalized, even if the ownership is added to 1, the coefficients in front of e will not actually have any effect on the result.
In summary, the formula is simplified to:
G (x, y) = e (x*x+y*y)/2
A 5 * 5 Gaussian kernel Calculation code is as follows:
1 usingSystem;2 3 namespaceTestshell4 {5 class Program6 {7 Static voidMain (string[] args)8 {9 Double[,] r = Calcgaussianblur (5);Ten for(inti =0; I < R.getlonglength (0); i++) One { A for(intj =0; J < R.getlonglength (1); J + +) - { -Console.Write ("{0:f4}\t", R[i, J]); the } - Console.WriteLine (); - } - Console.readkey (); + } - + Static Double[,] Calcgaussianblur (intsize) A { at Double[,] r =New Double[size, size]; - intCenter = (int) Math.floor (Size/2f); - Doublesum =0; - - for(inti =0; i < size; i++) - { in for(intj =0; J < size; J + +) - { to intx = Math.Abs (i-center); + inty = Math.Abs (J-center); - DoubleD =Calcitem (x, y); theR[i, J] =D; *Sum + =D; $ }Panax Notoginseng } - the for(inti =0; i < size; i++) + { A for(intj =0; J < size; J + +) the { +R[i, J]/=sum; - } $ } $ - returnR; - } the - Static DoubleCalcitem (intXinty)Wuyi { the returnMath.pow (MATH.E,-(x * x + y * y)/2d); - } Wu } -}
View Code
The results are as follows:
Unity shader The Gaussian blur of post-processing effects on the learning screen