views:

74

answers:

1

I need to fill an nXn matrix with a Gaussian filter programatically. I've been trying to work this out for a graphics project, but i'm a little stuck.

To clarify, an example 3x3 Gaussian filter matrix would be:

[1, 2, 1]
[2, 4, 2] / 16.0
[1, 2, 1]

+1  A: 

You just need a formula for a 2d gauss kernel and fill in your x and y values.

e.g. symmetric gauss kernel:

 double w = exp(-(fx*fx + fy*fy) / (2.0 * sigma * sigma)) / (2.0 * M_PI * sigma * sigma);

For an explanation with nice graphs see:

http://www.librow.com/articles/article-9

especially: 3. 2D case

tauran
Note that choice of sigma and gain (particularly for integer coefficients) are quite important, so you might want to add some further detail on how these are determined.
Paul R
Yes, that would be very helpful. Not sure what to put my standard deviation at to get 'good' results
Dfowj