I am trying to calculate the mean and variance using the 3X3 window above the image (hXw) in opencv ... here is my code ... are there any problems with this question? or is there any other effective way to do this in one go.?
int pi,a,b;
for(i=1;i<h-1;i++)
{
for(j=1;j<w-1;j++)
{ int sq=0,sum=0;
double mean=0;
double var=0;
for(a=-1;a<=1;a++)
{
for(b=-1;b<=1;b++)
{
pi=data[(i+a)*step+(j+b)];
sq=pi*pi;
sum=sum+sq;
mean=mean+pi;
}
}
mean=mean/9;
double soa=mean*mean;
double aos=sum/9;
double var=aos-soa;
}
}
source
share