I need to fill an nXn matrix with a Gaussian filter programatically. I've been trying to work开发者_C百科 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]
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
精彩评论