cv::meanStdDev returns inf sd for CV_32FC1 Mat in release build (Bug #4194)
Description
when using cv::meanStdDev on CV_32FC1, the mean is calculated correctly, but sd is always inf. This works correctly in debug build (both mean and sd are calculated) but fails in release build.
Example code
cv::Scalar mean;
cv::Scalar stddev;
cv::meanStdDev(im, mean, stddev);
stddev.val0 will be inf!
the range of values in the im is 5.0921e+13 4.95419e+20
History
Updated by Nisarg Thakkar about 10 years ago
Hi Sergey,
Can you attach the im
that you used?
Updated by be rak about 10 years ago
imho, we should not use 32bit floats to represent values in the [5.0921e+13 4.95419e+20] range, but i'm able to reproduce it:
Mat m(5,5,CV_32F); randu(m,Scalar(1.0e13),Scalar(1.0e20)); cv::Scalar mean; cv::Scalar stddev; cv::meanStdDev(m, mean, stddev); cerr << mean << endl; cerr << stddev << endl;
debug:
[4.57531e+019, 0, 0, 0] [2.96023e+019, 0, 0, 0]
release:
[4.57531e+019, 0, 0, 0] [1.#INF, 0, 0, 0]
Updated by Nisarg Thakkar almost 10 years ago
This seems a problem in IPP. If I remove the IPP for CV_32FC1, the result is calculated correctly. But, if the numbers reduce, IPP seems to work alright.
This code is present in the function cv::meanStdDev in the file modules/core/src/stat.cpp at the line:
#if (IPP_VERSION_X100 >= 801)
type == CV_32FC1 ? (ippiMeanStdDevFuncC1)ippiMean_StdDev_32f_C1R ://Aug 2013: bug in IPP 7.1, 8.0
#endif
Updated by Vadim Pisarevsky almost 10 years ago
- Category set to core
Updated by Vadim Pisarevsky almost 10 years ago
I agree with be rak that double precision should be used for such a range. working range for single precision operations is ~[-10**38, 10**38]. since meanStdDev sums the squared values as intermediate result, the range [10**13, 10**20] becomes [10**26, 10**40], which is too much. I doubt that it can be fixed. Even if we disable IPP, further optimizations of the C branch may yield the same "bug" again. So it's easier to say now - no, we are not going to handle such cases.
- Status changed from New to Cancelled
- Priority changed from Normal to Low