Counterintuitive comparison of matrices with NaN values (Bug #3011)


Added by Leonid Beynenson almost 12 years ago. Updated over 9 years ago.


Status:Open Start date:2013-05-06
Priority:Low Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:-
Affected version:branch '2.4' Operating System:
Difficulty: HW Platform:
Pull request:

Description

At the moment element-wise comparison of matrices works in OpenCV as follows:

  • the comparison operations A < B (and A > B) are calculated element-wise
  • but the comparison operations A <= B (and A >= B) are calculated as the logical negation of the compariosn A > 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

Revision c595457e
Added by Alexander Alekhin over 10 years ago

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

Also available in: Atom PDF