Free Online Image Tools

Edit photos directly in your web browser!

online-image-apps-at-fiveko
Home » Blog » Tutorials » Mean Filter: Box blur for fast noise reduction

Mean Filter: Box blur for fast noise reduction

The Mean filter is a linear low-pass blur photo filter where each pixel in the output image has average value of its neighboring pixels. The algorithm is also famous as Box blur and performs as convolution with average blur mask.

How does average filter works?

Even though the modern camera devices provide pretty good quality, often pictures are noisy. In such cases a common technique is to use low-pass filter to prevent high frequency noise artifacts.

We often call the Mean filter a “blurring” or “smoothing” filter, because the result is a blurry image.

In some articles you may find this operator as average filter, since for any pixel from image it takes the average value across its neighbors.

Like the Gaussian operator, this filter is also separable, so usually at a larger size it is better to run it once for rows and once for columns.

$\displaystyle{K}=\frac{1}{{9}}{\left[\begin{matrix}{1}&{1}&{1}\\{1}&{1}&{1}\\{1}&{1}&{1}\end{matrix}\right]}=\frac{1}{{3}}{\left[\begin{matrix}{1}&{1}&{1}\end{matrix}\right]}\ast\frac{1}{{3}}{\left[\begin{matrix}{1}\\{1}\\{1}\end{matrix}\right]}$
Mean filter with size 3×3

Moving Averages

In addition to mean filter separation it is possible to apply additional optimization called “moving averages”. This will reduce its complexity further to O(1).

The following steps describe the process:

  • Iterate through each row/column in a single pass
  • For the first pixel use the whole kernel size and calculate the sum and write the mean as output
  • For each next pixel use the sum from the previous step and subtract values which are no longer under the kernel.
  • Add the new values that come under the mask
  • Calculate the average sum and write it as output
mean filter size 9
Mean filter with size 9

Iterative Average filter (Box Blur)

We base our algorithm on the fact that Gaussian filter approximates well by multiple iterations of Average filter.

Equation (1) describes the standard deviation of mean filter with size n, since it corresponds to uniform probability distribution. In case of multiple iterations m, the standard deviation is result from equation 2.

Box blur standard deviation
Box blur standard deviation

Thus in order to calculate number of iterations m for known kernel size (e.g. n=3) and provided sigma, the equation could be represented as following:

Box blur iterations count
Iterations count based on standard deviation and kernel size

This iterative approach is suitable for fast parallel computing (GPU), where we can use WebGL to make a quick blur effect on photos.

Source Code for fast Image blur


See it Online

fivekogfx-mean-filter

WEB APPLET

See how it works in the browser!


Resources

TAGS:

Spectrum Audio Editor (Free!)

Effortless audio editing, made free. Edit sound like a pro with our online spectrum analyzer.

Sound CMD - Free Online Audio Editor

Fiveko Blog ↗

Discover articles and algorithms for image processing, programming, computer graphics, and more

Image Tools ↗

Free to use online image tools that run in a web browser. Apply photo effects to JPG, PNG, WebP and so on

Projects ↗

Small software projects and applications for various tasks: Graphics, Audio processing and others