Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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)