Introduce CV_COMP_CHISQR_ALT, an alternative method to calculate ChiSquare Histogram comparison
There's some disagreement about the correct formula. has its supporters, however, for texture analysis, the newly introduced formula became standard. The commit enables both uses without breaking backward compatibility. First contributor of this commit was sperrholz.
This commit is contained in:
@@ -948,7 +948,7 @@ int CV_ThreshHistTest::validate_test_results( int /*test_case_idx*/ )
|
||||
class CV_CompareHistTest : public CV_BaseHistTest
|
||||
{
|
||||
public:
|
||||
enum { MAX_METHOD = 4 };
|
||||
enum { MAX_METHOD = 5 };
|
||||
|
||||
CV_CompareHistTest();
|
||||
protected:
|
||||
@@ -1014,6 +1014,8 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
|
||||
result0[CV_COMP_INTERSECT] += MIN(v0,v1);
|
||||
if( fabs(v0) > DBL_EPSILON )
|
||||
result0[CV_COMP_CHISQR] += (v0 - v1)*(v0 - v1)/v0;
|
||||
if( fabs(v0 + v1) > DBL_EPSILON )
|
||||
result0[CV_COMP_CHISQR_ALT] += (v0 - v1)*(v0 - v1)/(v0 + v1);
|
||||
s0 += v0;
|
||||
s1 += v1;
|
||||
sq0 += v0*v0;
|
||||
@@ -1039,6 +1041,8 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
|
||||
result0[CV_COMP_INTERSECT] += MIN(v0,v1);
|
||||
if( fabs(v0) > DBL_EPSILON )
|
||||
result0[CV_COMP_CHISQR] += (v0 - v1)*(v0 - v1)/v0;
|
||||
if( fabs(v0 + v1) > DBL_EPSILON )
|
||||
result0[CV_COMP_CHISQR_ALT] += (v0 - v1)*(v0 - v1)/(v0 + v1);
|
||||
s0 += v0;
|
||||
sq0 += v0*v0;
|
||||
result0[CV_COMP_BHATTACHARYYA] += sqrt(v0*v1);
|
||||
@@ -1053,6 +1057,8 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
|
||||
}
|
||||
}
|
||||
|
||||
result0[CV_COMP_CHISQR_ALT] *= 2;
|
||||
|
||||
t = (sq0 - s0*s0/total_size)*(sq1 - s1*s1/total_size);
|
||||
result0[CV_COMP_CORREL] = fabs(t) > DBL_EPSILON ?
|
||||
(result0[CV_COMP_CORREL] - s0*s1/total_size)/sqrt(t) : 1;
|
||||
@@ -1067,6 +1073,7 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
|
||||
double v = result[i], v0 = result0[i];
|
||||
const char* method_name =
|
||||
i == CV_COMP_CHISQR ? "Chi-Square" :
|
||||
i == CV_COMP_CHISQR_ALT ? "Alternative Chi-Square" :
|
||||
i == CV_COMP_CORREL ? "Correlation" :
|
||||
i == CV_COMP_INTERSECT ? "Intersection" :
|
||||
i == CV_COMP_BHATTACHARYYA ? "Bhattacharyya" : "Unknown";
|
||||
|
Reference in New Issue
Block a user