Built with Processing

Fast Gaussian Blur Sourcecode

Note: if you are mainly interested in a very fast but "beautiful" blur for visual effects then you should check out my Fast Blur Deluxe which is several times faster than this implementation.
A Fast Gaussian Blur Implementation

One of my first steps with Processing. I am a fan of blurring. Especially as you can use blurred images as a base for other effects. So this is something I might get back to in later experiments.

What you see is an attempt to implement a Gaussian Blur algorithm which is exact but fast. I think that this one should be relatively fast because it uses a special trick by first making a horizontal blur on the original image and afterwards making a vertical blur on the pre-processed image. This is a mathematical correct thing to do and reduces the calculation a lot.

In order to avoid the overhead of function calls I unrolled the whole convolution routine in one method. This may not look nice and not be good OOP, but it brings a huge performance boost.

One idea I still have to improve this version is to use just integer variables.

Update: I've managed to speed up the algorithm significantly by making all calculations in integers and by replacing the multiplications in the inner loops with a precalculated lookup table.

Note: as some people correctly noticed the blur kernel I use here is not really "gaussian". But as the purpose of this filter is mainly to be used for visual effects to me that doesn't really matter as long as the output looks good - if you need a mathematically correct Gaussian kernel you might have to change the code or use a different implementation.

The Y-position of your mouse controls the radius of the blur in this example.

The painting used for demonstration is "Cecelia" by fabulous Mark Ryden.