Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

meanStdDev seems to have a bug? Or am I using it wrong?

When I use meanStdDev for an unsigned int array with more than a million elements (m = 1228800x1 matrix, by reshaping a single channel 1280x960 image), I seem to get an overflow or something like that.

Code snippet:

m=cvarrToMat(img, true);
m=m.reshape(0,1); //makes m a 1228800x1 matrix
m.copyTo(m1);
meanStdDev(m1, meanframe1, stdframe1);

If I use a 128x96 matrix as an input, I get values like meanframe(0)=3067.9 stdframe1(0)=107.072 which seem to be correct for a dark frame from a cmos camera.

But if I use a 1280x960 image as input under the same conditions, I get meanframe(0)=-454.69 stdframe1(0)=14832.8 which is absolutely wrong - negative number for mean!

meanStdDev seems to have a bug? Or am I using it wrong?

When I use meanStdDev for an unsigned int array with more than a million elements (m = 1228800x1 matrix, by reshaping a single channel 1280x960 image), I seem to get an overflow or something like that.

Code snippet:

m=cvarrToMat(img, true);
m=m.reshape(0,1); //makes m a 1228800x1 matrix
m.copyTo(m1);
meanStdDev(m1, meanframe1, stdframe1);

If I use a 128x96 matrix as an input, I get values like meanframe(0)=3067.9 stdframe1(0)=107.072 which seem to be correct for a dark frame from a cmos camera.

But if I use a 1280x960 image as input under the same conditions, I get meanframe(0)=-454.69 stdframe1(0)=14832.8 which is absolutely wrong - negative number for mean!

Additional info:

meanframe1=mean(m1);

gives the correct answer even for large matrices. So, meanStdDev along seems to be the culprit....

meanStdDev seems to have a bug? Or am I using it wrong?

When I use meanStdDev for an unsigned int array with more than a million elements (m = 1228800x1 matrix, by reshaping a single channel 1280x960 image), I seem to get an overflow or something like that.

Code snippet:

m=cvarrToMat(img, true);
m=m.reshape(0,1); //makes m a 1228800x1 matrix
m.copyTo(m1);
meanStdDev(m1, meanframe1, stdframe1);

If I use a 128x96 matrix as an input, I get values like meanframe(0)=3067.9 stdframe1(0)=107.072 which seem to be correct for a dark frame from a cmos camera.

But if I use a 1280x960 image as input under the same conditions, I get meanframe(0)=-454.69 stdframe1(0)=14832.8 which is absolutely wrong - negative number for mean!

Additional info:

meanframe1=mean(m1);

gives the correct answer even for large matrices. So, meanStdDev along seems to be the culprit....

meanStdDev seems to have a bug? Or am I using it wrong?

When I use meanStdDev for an array with more than a million elements (m = 1228800x1 matrix, by reshaping a single channel 1280x960 image), I seem to get an overflow or something like that.

Code snippet:

m=cvarrToMat(img, true);
m=m.reshape(0,1); //makes m a 1228800x1 matrix
m.copyTo(m1);
meanStdDev(m1, meanframe1, stdframe1);

If I use a 128x96 matrix as an input, I get values like meanframe(0)=3067.9 stdframe1(0)=107.072 which seem to be correct for a dark frame from a cmos camera.

But if I use a 1280x960 image as input under the same conditions, I get meanframe(0)=-454.69 stdframe1(0)=14832.8 which is absolutely wrong - negative number for mean!

Additional info:

meanframe1=mean(m1);

gives the correct answer even for large matrices. So, meanStdDev along seems to be the culprit....

More additional info:

my own code for StdDev also gives correct results,

meanframe1=mean(m1);
double dstddev = 0.0;
                                    double dmean = meanframe1(0); // only one channel

                                    for (int i = 0; i < w*h; i++)
                                    {
                                        dstddev += (dmean - m1.at<ushort>(i)) * (dmean - m1.at<ushort>(i));
                                    }

                                    dstddev = sqrt(dstddev / (w*h));

                                    std::cout<<"mean="<<meanframe1(0)<<std::endl;
                                    std::cout<<"stddev="<<dstddev<<std::endl;