Hello, I need to compare two histograms for my project. I am working on normalized histograms by using the following function call:

//Assuming that histogram is a cv::Mat and is valid
cv::normalize(histogram, histogram, 1.0);


I am using cv::compareHist() to compare the histograms. I have tried the all four methods for comparison with OpenCV macros: CV_COMP_CORREL, CV_COMP_CHISQR, CV_COMP_INTERSECT, CV_COMP_BHATTACHARYYA.

The problem is that: When analyzing the comparison results, CV_COMP_INTERSECT comparison method produce values bigger than 1 although two histograms are normalized. It is stated on Learning OpenCV: Computer Vision with the OpenCV library (page 202):

If both histograms are normalized to 1, then a perfect match is 1 and a total mismatch is 0.

Best wishes.

edit retag close merge delete

Sort by » oldest newest most voted

When you use CV_COMP_INTERSECT comparison method on two histograms that are perfectly match, your result will be equal to sum of values of a histogram. i.e. your result will be equal to L1 norm of histogram.

When you used normalize() function, you set only 3 first parameters. And so other parameters were used with their default values. By default it uses L2 norm. i.e. after using normalize(), sum of squares of values of histogram was set to 1.

To fix your problem you should use:

cv::normalize(histogram, histogram, 1.0, 0.0, NORM_L1);

more

Thank you so much. I have understood where the mistake was.

( 2012-12-23 08:34:48 -0500 )edit

Official site

GitHub

Wiki

Documentation