Counterintuitive comparison of matrices with NaN values (Bug #3011)
Description
At the moment element-wise comparison of matrices works in OpenCV as follows:
- the comparison operations
A < B
(andA > B
) are calculated element-wise - but the comparison operations
A <= B
(andA >= B
) are calculated as the logical negation of the compariosnA > B
(correspondingly,A <B
)
(see the code of the function cv::compare
in the file source:modules/core/src/arithm.cpp and the template function cmp_
in the same file)
Since in C++ the operations <
, >
, <=
, and >=
with NaN values always return false
, there is the following counterintuitive behavior:
if a matrix A contains only NaN values, we will have
countNonZero(A < 0.5) ==> 0; countNonZero(A > 0.5) ==> 0; countNonZero(A <= 0.5) ==> A.total(); countNonZero(A >= 0.5) ==> A.total();
This may be fixed if the comparison functions will make element-wise calculations for non-strict inequalities too. But in this case all the optimizations (SSE, etc) should be changed too.
Associated revisions
Merge pull request #3011 from vbystricky:oclopt_morthosmall
History
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4565