# Question About Histogram Comparison return value

I am having confusion in understanding compareHist() Method ,Can't seem to understand whats the meaning of return value by each different method. They all return different value. All i want to know if both histogram are matched then the value should be 1.0 if does not match then it should be 0.0 meaning picture matches perfectly.

Can someone explain me in Scale wise the meaning of each result value of each methods

*CV_COMP_CORREL Correlation

*CV_COMP_CHISQR Chi-Square

*CV_COMP_INTERSECT Intersection

*CV_COMP_BHATTACHARYYA Bhattacharyya distance

*CV_COMP_HELLINGER Synonym for CV_COMP_BHATTACHARYYA

edit retag close merge delete

Sort by » oldest newest most voted

Not all scores are bounded:

• CV_COMP_CORREL: [-1;1] where 1 is perfect match and -1 is the worst.
• CV_COMP_CHISQR: [0;+infinty] where 0 is perfect match and mismatch is unbounded (see doc for equation of comparison)
• CV_COMP_INTERSECT: [0;1] (if histograms are normalized) where 1 is perfect match and 0 mismatch.
• CV_COMP_BHATTACHARYYA and CV_COMP_HELLINGER: [0;1] where 0 is perfect match and 1 mismatch.

Equations of methods are here. An explaination with schema is available in ''Learning OpenCV Computer Vision with OpenCV Library, from G. Bradski and A. Kaehler'' p. 203.

more

@ mathieum if the values are some what closer to perfect i.e For CV_COMP_CORREL = 0.99 Then we can say its almost a perfect match. I wanna know that what if the value is greater then 1 in CV_COMP_INTERSECT i.e 1.56 would i say its a perfect match ?

( 2013-02-28 00:36:11 -0500 )edit

It's depend on your histograms… if they are normalized, you have a problem, if not, it's hard to say… it could be bad… => normalize your histograms and try again.

( 2013-02-28 02:55:49 -0500 )edit

There are different methods how to compare histograms. Each method uses a different distance (or error) function. All distance functions should return a value >= 0, where 0 means, that the histograms are identical. So, if you just want to test the histograms for equality, then you can use any method. If it returns 0, then they are equal, if they return a value greater than 0, they are different. You could also use a threshold to permit very similar histograms to match as well (e.g. x < 0.05 => match) If you're interested in HOW similar the histograms are, then it might be relevant, which method you use, because they have different error functions leading to different results.

Histogram example H1:

| |  |
| |  |   |
----------


Histogram example H2:

         |
|
|
| |  |   |
----------


Histogram example H3:

|||| ||  |
----------


Which one is closer to H1? H2 or H3?

Let's say you have an image I1 having the histogram H1. Now, you take I1 and just add a white border to it. This might result in a histogram like H2.

Or you blur I1, then you get a histogram like H3.

There is no general right answer to this. Different distance functions will put an accent on different aspects and lead to different results.

EDIT

Not all methods above actually use proper distance functions, as I realized when I read Mathieu's correct answer. But their results can be made to distance functions:

• for CV_COMP_INTERSECT: dist = 1 - result
• for CV_COMP_CORREL: dist = 2 - (result + 1)
more

Official site

GitHub

Wiki

Documentation