StrataQuest Home StrataQuest Glossary Average filter
Image Processing & Correction

Average filter

The simplest convolutional smoother — uniform weights summing to one

View
Definition
An average filter computes each output pixel as the arithmetic mean of an N×N neighborhood centered on the corresponding input pixel. Formally, with input image I and an N×N window: O(x, y) = (1/N²) · Σᵢ Σⱼ I(x+i, y+j) for i, j ∈ [−⌊N/2⌋, ⌊N/2⌋]. As a convolutionLoading..., the kernel is the constant matrix K(i, j) = 1/N², summing to 1, which preserves overall brightness. The cost is linear in image area times kernel area — O(WHN²) per image — though box filters admit O(WH) implementations via running sums independent of N.
Supporting
H&EDSPTCH
Video · Supporting
Uniform weights, no preference
Every pixel in the window contributes equally
Window size sets the smoothing scale
Bigger N, more smoothing, more blur
Frequency-domain view — a sinc
The box kernel's Fourier transform reveals its limitations
Outliers shift the mean
One hot pixel raises every nearby output

The math, in two registers

The discrete N×N box average is the convolution of the input with the kernel K(i, j) = 1/N² for all (i, j) in [−⌊N/2⌋, ⌊N/2⌋]² and 0 elsewhere. Written out for a 3×3 case at output position (x, y):

O(x, y) = (1/9) · [I(x−1,y−1) + I(x,y−1) + I(x+1,y−1) + I(x−1,y) + I(x,y) + I(x+1,y) + I(x−1,y+1) + I(x,y+1) + I(x+1,y+1)]

Two computational notes worth knowing. First, the box average is separable: the 2D N×N box equals the outer product of two 1D boxes of length N. This means running rows first, then columns, costs O(WHN) instead of O(WHN²). Second, the box average admits a constant-time-per-pixel implementation regardless of N: maintain a running sum that adds the entering column and subtracts the exiting one as the window slides. This brings the cost to O(WH) — independent of window size. Most production implementations use this trick.

Simplified

For a 3×3 window centered at pixel (x, y), the output is the sum of the 9 pixels in that window divided by 9. For a 5×5, sum the 25 pixels and divide by 25. The math doesn't get more complicated than that. Larger windows just sum more pixels and divide by a larger denominator.

Efficient implementations don't actually recompute the sum at every pixel — they slide a running total across the image, adding the new edge and subtracting the old. This trick makes the filter run at the same speed regardless of how large the window is.

Share This Term
Term Connections