Gaussian blur describes blurring an image by aGaussian function. It is a widelyused effect in graphics software, typically to reduce image noise and reducedetail. The visual effect of this blurring technique is a smoothblur resembling that of viewing the image through a translucent screen, distinctlydifferent from the bokeheffect produced by an out-of-focus lens or the shadow of an objectunder usual illumination. Gaussian smoothing is also used as apre-processing stage in computer vision algorithms in order toenhance image structures at different scales—see scale-space representation and scale-spaceimplementation.
Mathematically, applying a Gaussian blur to an image is the sameas convolvingthe image with a Gaussian function; this is also knownas a two-dimensional Weierstrass transform. Bycontrast, convolving by a circle (i.e., a circular box blur) would moreaccurately reproduce the bokeh effect. Since the Fouriertransform of a Gaussian is another Gaussian, applying aGaussian blur has the effect of reducing the image's high-frequencycomponents; a Gaussian blur is thus a low passfilter.
Mechanics
The Gaussian blur is a type of image-blurring filter that uses aGaussian function (which is also used for the normaldistribution in statistics) for calculating the transformation to apply toeach pixel in the image. The equation of a Gaussian function in onedimension is
In two dimensions, it is the product of two such Gaussians, oneper direction:
Where x is the distance from the origin in thehorizontal axis, y is the distance from the origin in thevertical axis, and σ is the standard deviation of theGaussian distribution. When applied in two dimensions, this formulaproduces a surface whose contours are concentriccircles with a Gaussian distribution from the center point.Values from this distribution are used to build a convolution matrix whichis applied to the original image. Each pixel's new value is set toa weighted average of that pixel'sneighborhood. The original pixel's value receives the heaviestweight (having the highest Gaussian value) and neighboring pixelsreceive smaller weights as their distance to the original pixelincreases. This results in a blur that preserves boundaries andedges better than other, more uniform blurring filters; see alsoscale-spaceimplementation.
In theory, the Gaussian function at every point on the imagewill be non-zero, meaning that the entire image would need to beincluded in the calculations for each pixel. In practice, whencomputing a discrete approximation of the Gaussian function, pixelsat a distance of more than 3σ are small enough to beconsidered effectively zero. Thus contributions from pixels outsidethat range can be ignored. Typically, an image processing programneed only calculate a matrix with dimensions (where is the ceiling function) to ensurea result sufficiently close to that obtained by the entire gaussiandistribution.
In addition to being circularly symmetric, the Gaussian blur canbe applied to a two-dimensional image as two independentone-dimensional calculations, and so is termed linearlyseparable. That is, the effect of applying the two-dimensionalmatrix can also be achieved by applying a series ofsingle-dimensional Gaussian matrices in the horizontal direction,then repeating the process in the vertical direction. Incomputational terms, this is a useful property, since thecalculation can be performed in time (where h is height and w iswidth; see Big O notation), as opposed to for a non-separable kernel.
Applying multiple, successive gaussian blurs to an image has thesame effect as applying a single, larger gaussian blur, whoseradius is the square root of the sum of the squares of the blurradii that were actually applied. For example, applying successivegaussian blurs with radii of 6 and 8 gives the same results asapplying a single gaussian blur of radius 10, since . Because of thisrelationship, processing time cannot be saved by simulating agaussian blur with successive, smaller blurs — the time requiredwill be at least as great as performing the single large blur.
Gaussian blurring is commonly used when reducing the size of animage. When downsampling an image, it is common toapply a low-pass filter to the image prior to resampling. This isto ensure that spurious high-frequency information does not appearin the downsampled image (aliasing). Gaussian blurs have niceproperties, such as having no sharp edges, and thus do notintroduce ringing into the filtered image.
Low-pass filter
Gaussian blur is a low-pass filter, attenuating highfrequency signals.
Its amplitude Bodeplot (the log scale in the frequency domain) is a parabola.
Sample Gaussian matrix
This is a sample matrix, produced by sampling the Gaussian filterkernel (with σ = 0.84089642) at the midpoints of each pixel and thennormalising. Note that the center element (at [4, 4]) has the largestvalue, decreasing symmetrically as distance from the center increases.
Note that 0.22508352 (the central one) is 1177 times larger than 0.00019117 which is just outside 3σ.
Implementation
A Gaussian Blur effect is typically generated by convolving animage with a kernel of Gaussian values. In practice, it is best totake advantage of the Gaussian Blur’s linearly separable propertyby dividing the process into two passes. In the first pass, aone-dimensional kernel is used to blur the image in only thehorizontal or vertical direction. In the second pass, anotherone-dimensional kernel is used to blur in the remaining direction.The resulting effect is the same as convolving with atwo-dimensional kernel in a single pass, but requires fewercalculations.
Discretisation is typically achieved by sampling the Gaussianfilter kernel at discrete points, normally at positionscorresponding to the midpoints of each pixel. This reduces thecomputational cost but, for very small filter kernels, pointsampling the Gaussian function with very few samples leads to alarge error. In these cases, accuracy is maintained (at a slightcomputational cost) by integration of the Gaussian function overeach pixel's area.
When converting the Gaussian’s continuous values into thediscrete values needed for a kernel, the sum of the values will bedifferent from 1. This will cause a darkening or brightening of theimage. To remedy this, the values can be normalized by dividingeach term in the kernel by the sum of all terms in the kernel.