Ask Your Question
2

Question About Histogram Comparison return value

asked 2013-02-27 07:33:56 -0600

aftab gravatar image

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 flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
5

answered 2013-02-27 07:46:00 -0600

updated 2013-02-27 07:46:25 -0600

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.

edit flag offensive delete link more

Comments

@ 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 ?

aftab gravatar imageaftab ( 2013-02-28 00:36:11 -0600 )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.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-02-28 02:55:49 -0600 )edit
2

answered 2013-02-27 08:03:02 -0600

Ben gravatar image

updated 2013-02-27 08:10:14 -0600

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)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-02-27 07:33:56 -0600

Seen: 5,508 times

Last updated: Feb 27 '13