# mean and variance of a gaussian filter mask

This topic is 4757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i have a 3 x 3 gaussian filter mask: 1 2 1 2 4 2 1 2 1 does anyone know how to calculate mean and variance of this mask ? thanks, markus

##### Share on other sites
Maybe I'm wrong, but it is a 2d discrete function, so the mean is:

double mean,s=0;int x,y;for (x=0;x<3;x++)   for (y=0;y<3;y++)      s+=filter[x][y];mean=s/9.0;

Variance is:
double v,s=0;int x,y;for (x=0;x<3;x++)   for (y=0;y<3;y++)   {      double diff=(filter[x][y]-mean);      s+=diff*diff;   }}v=s/9.0;

Hope this is right and helps.