Ask Your Question
0

Problem about the source codes of otsu-threshold

asked 2013-09-19 01:36:58 -0600

stereomatching gravatar image

updated 2013-09-19 03:15:28 -0600

berak gravatar image

The codes from the files thresh.cpp, the function name is getThreshVal_Otsu_8u

if( std::min(q1,q2) < FLT_EPSILON || 
            std::max(q1,q2) > 1. - FLT_EPSILON )
            continue;

As far as I know,

q1 + q2 = 1--(1)
q1 = 1 - q2--(2)
q2 = 1 - q1--(3)

That means if

q1 < FLT_EPSILON

then 1 - q1 will satisfy

1 - q1 > 1 - FLT_EPSILON

In other words, if std::min(q1,q2) < FLT_EPSILON, then std::max(q1,q2) > 1. - FLT_EPSILON should satisfy too.So why do the codes need to do double check? Why don't just use

if( std::min(q1,q2) < FLT_EPSILON)
                continue;
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-19 04:03:55 -0600

Moster gravatar image

Probably this has something to do with float precision. It might happen that one of the conditions returns false/true although it shouldnt with real numbers.

edit flag offensive delete link more

Comments

This look reasonable, do you know other possibility?

stereomatching gravatar imagestereomatching ( 2013-09-19 04:46:03 -0600 )edit

No, actually I dont. This is most likely the reason

Moster gravatar imageMoster ( 2013-09-22 14:40:34 -0600 )edit

Question Tools

Stats

Asked: 2013-09-19 01:36:58 -0600

Seen: 266 times

Last updated: Sep 19 '13