Math in… Gaussian Blur

Photo by Johannes Plenio

One of the simplest image blurring algorithms is the Gaussian blur. It is based on the Gaussian function, which comes up frequently in probability and statistics in normal distributions.

Since images are 2D, it uses a 2-variable Gaussian, which graphs as a bell-shaped surface:

The surface is tallest in the center and tapers off quickly and smoothly to a near-zero height as x and y grow larger in magnitude. The constant σ impacts how quickly it tapers off.

When applying a Gaussian blur, the algorithm takes each pixel and changes its color to a weighted average of its color and the colors of its neighbors. The algorithm centers the Gaussian function at the pixel it wants to blur:

The pixels that fall under the surface are then averaged together to get the central pixel's "blurred" color. Pixels are weighted according to the height of the surface above them, so the blurred pixel ends up looking more like the pixels close to it and less like the pixels far away from it.

Updating every pixel of an image to a new color in this way results in a Gaussian blur!

By changing the value of σ, the shape of the surface can be adjusted so that far away pixels are counted more or less in the average.

A slider that allows you choose more or less blur is toggling this value.

The Gaussian is a nice function to use for blurring because the influence exerted by a nearby or far-away pixel is based on our usual radial sense of distance.

A pixel's "blurred" color could instead be decided by the pixels in a surrounding square or rectangle. Such box filter blurs work more naturally with a rectangular array of pixels.

How else could you use math to alter an image?

Nick Rauh

Nick is a Seattle-based mathematician who has spent his career teaching at colleges and designing math activities for K-12 children. He is currently the Mathematician in Residence at the Seattle Universal Math Museum.

https://maththem.blogspot.com
Previous
Previous

Math in… Groundhog Day

Next
Next

Math in… Vector Fields