OpenCV  3.4.9
Open Source Computer Vision
Histogram Comparison

Prev Tutorial: Histogram Calculation

Next Tutorial: Back Projection

Goal

In this tutorial you will learn how to:

Theory

Code

Explanation

Results

  1. We use as input the following images:
    Histogram_Comparison_Source_0.jpg
    Base_0
    Histogram_Comparison_Source_1.jpg
    Test_1
    Histogram_Comparison_Source_2.jpg
    Test_2
    where the first one is the base (to be compared to the others), the other 2 are the test images. We will also compare the first image with respect to itself and with respect of half the base image.
  2. We should expect a perfect match when we compare the base image histogram with itself. Also, compared with the histogram of half the base image, it should present a high match since both are from the same source. For the other two test images, we can observe that they have very different lighting conditions, so the matching should not be very good:
  3. Here the numeric results we got with OpenCV 3.4.1:
    *Method* Base - Base Base - Half Base - Test 1 Base - Test 2
    *Correlation* 1.000000 0.880438 0.20457 0.0664547
    *Chi-square* 0.000000 4.6834 2697.98 4763.8
    *Intersection* 18.8947 13.022 5.44085 2.58173
    *Bhattacharyya* 0.000000 0.237887 0.679826 0.874173
    For the Correlation and Intersection methods, the higher the metric, the more accurate the match. As we can see, the match base-base is the highest of all as expected. Also we can observe that the match base-half is the second best match (as we predicted). For the other two metrics, the less the result, the better the match. We can observe that the matches between the test 1 and test 2 with respect to the base are worse, which again, was expected.