Hubbry Logo
Box blurBox blurMain
Open search
Box blur
Community hub
Box blur
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Box blur
Box blur
from Wikipedia
An example of an image blurred using a box blur

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.

Extensions

[edit]
  • Gwosdek, et al. has extended Box blur to take a fractional radius: the edges of the 1-D filter are expanded with a fraction. It makes slightly better gaussian approximation possible due to the elimination of integer-rounding error.[3]
  • Mario Klingemann has a "stack blur" that tries to better emulate gaussian's look in one pass by stacking weights: [4][5] The triangular impulse response it forms decomposes to two rounds of box blur.[3]
  • Stacked Integral Image by Bhatia et al. takes the weighted average of a few box blurs to fit the gaussian response curve.[3]

Implementation

[edit]

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]

  • Introducing an alpha channel to represent the absence of colors;
  • Extending the boundary by filling in values, ranked by quality:
    • Fill in a mirrored image at the border
    • Fill in a constant color extending from the last pixel
    • Pad in a fixed color

A number of optimizations can be applied when implementing the box blur of a radius r and N pixels:[6]

  1. The box blur is a separable filter, so that only two 1D passes of averaging 2 r + 1 pixels will be needed, one horizontal and one vertical, for each pixel. This lowers the complexity from O(Nr2) to O(Nr). In digital signal processing terminology, each pass is a moving-average filter.
  2. Accumulation. Instead of discarding the sum for each pixel, the algorithm re-uses the previous sum, and updates it by subtracting away the old pixel and adding the new pixel in the blurring range. A summed-area table can be used similarly. This lowers the complexity from O(Nr) to O(N).
  3. When being used in multiple passes to approximate a Gaussian blur, the cascaded integrator–comb filter construction allows for doing the equivalent operation in a single pass.[7]

See also

[edit]

References

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
A box blur, also known as a box filter, is a fundamental low-pass filtering technique in and that smooths an by replacing each 's value with the of the pixel values within a surrounding rectangular neighborhood, typically square-shaped. This operation is performed via with a uniform kernel where every element has equal weight, normalized by the kernel's size to preserve the overall image intensity. The result produces a uniform blurring effect that reduces high-frequency details such as edges and noise while attenuating spatial frequencies, though not ideally due to its non-monotonic frequency response in the Fourier domain. Box blurs are computationally efficient, especially when implemented separably: the 2D convolution can be decomposed into two sequential 1D convolutions (horizontal and vertical passes), reducing the time complexity from O(n2)O(n^2) to O(2n)O(2n) per pixel for an n×nn \times n kernel, where nn is the kernel dimension. This separability makes it suitable for real-time applications in graphics rendering and video processing. In the frequency domain, the box filter's sinc-like response causes it to pass certain high frequencies without attenuation, potentially leading to artifacts like ringing, unlike smoother filters such as Gaussian blurs. Despite these limitations, box blurs are widely used for , in downsampling, and as a fast approximation to more sophisticated blurs; repeated applications of box filters can closely mimic a through the , as multiple uniform averagings converge toward a . In practice, larger kernels yield stronger blurring, and optimizations like integral images enable O(1)O(1) computation for arbitrary box sizes, enhancing performance in large-scale image manipulations.

Fundamentals

Definition

Box blur is a spatial domain linear filter in digital image processing, where each pixel in the output image is computed as the average value of the pixels within a rectangular neighborhood surrounding the corresponding input pixel. This neighborhood, often square-shaped, gives the filter its name due to the uniform "box" region it considers. Unlike weighted blur filters such as Gaussian blur, box blur assigns equal weight to every pixel in the kernel, resulting in a simple uniform averaging operation that smooths the image by reducing high-frequency details. For instance, in a one-dimensional case, a box blur with a kernel size of three would replace each pixel value with the average of itself and its two immediate neighbors, effectively blending adjacent intensities to soften transitions. Box blur emerged as a foundational convolution-based filtering technique in the early development of during the 1960s and 1970s, particularly in applications like imagery at institutions such as the , where basic linear filters were adapted from one-dimensional methods. It lacks a specific inventor, instead representing a straightforward extension of averaging principles in nascent systems of that era. The underlying operation relies on , which slides the filter across the image to compute localized averages.

Basic Principles

Box blur functions as a in image processing, attenuating high-frequency components while preserving lower-frequency details, which results in smoothing the image by reducing sharp transitions between pixels. This filtering effect averages pixel values over a rectangular neighborhood, effectively dampening rapid intensity changes that correspond to edges and fine textures. Visually, box blur produces a uniform softening of edges across the image due to its equal weighting of neighboring pixels, which helps reduce noise by suppressing high-frequency variations often associated with sensor artifacts or grain. When implemented with square kernels, box blur exhibits isotropic behavior in the horizontal and vertical directions, applying the same averaging extent equally along the cardinal axes. Repeated applications of this square kernel filter tend to produce blur patterns that approximate circular shapes, as the cumulative effect diffuses intensities more evenly in all directions. The repeated application of box blur serves as a foundational approximation for more natural blurring effects, conceptually drawing from the , where successive convolutions with a kernel converge toward a Gaussian distribution.

Mathematical Formulation

Kernel Representation

The box blur kernel, also known as a or average filter kernel, is defined as a rectangular matrix filled with identical values, each equal to the reciprocal of the total number of elements in the matrix to ensure normalization. For a square kernel of size n×nn \times n, where n=2r+1n = 2r + 1 and rr is the blur radius, the kernel consists of n2n^2 elements, each set to 1n2\frac{1}{n^2}. This weighting averages the values within the kernel's neighborhood, producing an equal contribution from each covered . A representative example is the 3×3 kernel corresponding to a radius of 1, given by 19[111111111].\frac{1}{9} \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{bmatrix}.
Add your contribution
Related Hubs
User Avatar
No comments yet.