Thursday, April 11, 2013

2D Gaussian Blur

2D Gaussian Blur (3x3)

In computer graphics you sometimes need to blur the image. Many Shader algorithms require a blur for example Bloom, SSAO, Motion Blur, Depth of Field, etc. 2D Gausian blur is a simple way to blur an image although it has some problems. It is inefficient as it has to do a lot of texture reads. Although a obvious better choice then Box Blur because Gaussian can have the same amount of texture reads but doesn't have the nasty aliasing box blur does.

The algorithm is just like Box blurs where you add the color contribution of each adjacent pixel is a 3x3 matrix (where the current fragment is in the center) but this time instead of dividing by 9 at the end we multiply each pixel by a weighting before adding it to the color sum. the sum of the weights have to add up to 1 and the weights are calculated by either the Gaussian graph or pascals triangle (gives a nice approximation). The weights for each pixel for a 3x3 2D Gaussian blur is below.

Not normalized
1  2  1
2  4  2
1  2  1

normalized
0.0625  0.125  0.0625 
0.125   0.25    0.125
0.0625  0.125 0.0625

here are some examples of a Gaussian Blur
http://www.borisfx.com/graffiti/new_filters.php
http://www.java2s.com/Code/Java/Advanced-Graphics/GaussianBlurDemo.htm

http://www.jhlabs.com/ip/blurring.html

No comments:

Post a Comment