Average and variance of the image in one pass

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;//square of average
        double aos=sum/9;//mean of squares
        double var=aos-soa;//variance
    }
}
+3
source share
4 answers

, (), . , . , , , , . , .

. , " " .

+3

, ., , .

, , ; , . , , , .

+3

. , .

0

! . . , , .

0

Source: https://habr.com/ru/post/1740476/


All Articles