The Gaussian kernel
The Gaussian weights neighbors by their distance from the center, with a standard deviation that sets the amount of blur:
It never reaches zero, so in practice it is cut off at , which keeps 99.7 % of the weight in each direction, and the samples are normalized to sum to 1. A kernel for is then pixels wide.
Separability
The Gaussian is a separable kernel: the exponential of a sum is a product, so the 2D Gaussian factors into a product of two 1D Gaussians,
As a matrix, the 2D kernel is the outer product of a column and a row vector, a matrix of rank 1. A small example with integer weights:
Because convolution is associative, filtering with the 2D kernel is the same as filtering with the row kernel and then with the column kernel:
An image with a filter requires multiplications, the two passes only . The saving grows with the filter size: for a filter the speedup is . Every kernel of rank 1 is separable, for example the box filter and the Sobel filter ; whether a kernel is separable, and into which vectors, can be read off its singular value decomposition.
Repeated box filtering
Convolving a box filter with itself gives a triangle, then a piecewise quadratic, and so on: if you convolve many times with a box filter, it converges to a Gaussian. This is the central limit theorem: the sum of many independent random variables tends to a normal distribution. Variances add under convolution, and a box of width has variance , so boxes give
A box filter can be computed with a running sum at a cost that does not depend on its width, so a few box passes are a cheap way to approximate a large Gaussian. A Gaussian convolved with a Gaussian is again a Gaussian, and the variances add as well, : convolving two times with width is the same as convolving once with width .
Try this
- Increase to 5: the kernel is 31 × 31 pixels, and the two passes need 62 instead of 961 multiplications per pixel.
- Look at the line groups of the test chart after the horizontal pass: the vertical stripes are blurred, the horizontal ones are still sharp.
- Check the difference between the two passes and the direct 2D filter in the values panel: it is only rounding error.
- Set the number of box passes to 1, 2 and 3: box, triangle, and something already hard to tell from the Gaussian.
- Compare with 10 passes and with 1 pass: the same variance , but very different shapes.
- Blur the zone plate with a small and a large : the Gaussian removes the fine rings first, starting from the corners.