Loading AI tools
Graphic-art effect From Wikipedia, the free encyclopedia
A box blur (also known as a box linear filter) is a spatial domain linear filter in which each pixel in the resulting image has a value equal to the average value of its neighboring pixels in the input image. It is a form of low-pass ("blurring") filter. A 3 by 3 box blur ("radius 1") can be written as matrix
Due to its property of using equal weights, it can be implemented using a much simpler accumulation algorithm, which is significantly faster than using a sliding-window algorithm.[1]
Box blurs are frequently used to approximate a Gaussian blur.[2] By the central limit theorem, repeated application of a box blur will approximate a Gaussian blur.[3]
In the frequency domain, a box blur has zeros and negative components. That is, a sine wave with a period equal to the size of the box will be blurred away entirely, and wavelengths shorter than the size of the box may be phase-reversed, as seen when two bokeh circles touch to form a bright spot where there would be a dark spot between two bright spots in the original image.
The following pseudocode implements a 3x3 box blur.
Box blur (image)
{
set newImage to image;
For x /*row*/, y/*column*/ on newImage do:
{
// Kernel would not fit!
If x < 1 or y < 1 or x + 1 == width or y + 1 == height then:
Continue;
// Set P to the average of 9 pixels:
X X X
X P X
X X X
// Calculate average.
Sum = image[x - 1, y + 1] + // Top left
image[x + 0, y + 1] + // Top center
image[x + 1, y + 1] + // Top right
image[x - 1, y + 0] + // Mid left
image[x + 0, y + 0] + // Current pixel
image[x + 1, y + 0] + // Mid right
image[x - 1, y - 1] + // Low left
image[x + 0, y - 1] + // Low center
image[x + 1, y - 1]; // Low right
newImage[x, y] = Sum / 9;
}
Return newImage;
}
The example does not handle the edges of the image, which would not fit inside the kernel, so that these areas remain unblurred. In practice, the issue is better handled by: [3]
A number of optimizations can be applied when implementing the box blur of a radius r and N pixels:[6]
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.