![]() |
OpenCV
Open Source Computer Vision
|
Prev Tutorial: Histogram Calculation
Next Tutorial: Back Projection
Original author | Ana Huamán |
Compatibility | OpenCV >= 3.0 |
In this tutorial you will learn how to:
Load the base image (src_base) and the other two test images:
Convert them to HSV format:
Also, create an image of half the base image (in HSV format):
Initialize the arguments to calculate the histograms (bins, ranges and channels H and S).
Calculate the Histograms for the base image, the 2 test images and the half-down base image:
Apply sequentially the 6 comparison methods between the histogram of the base image (hist_base) and the other histograms:
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.
Here the numeric results we got with OpenCV 4.12.0:
Method | Base - Base | Base - Half | Base - Test 1 | Base - Test 2 |
---|---|---|---|---|
Correlation | 1.000000 | 0.880438 | 0.20457 | 0.065752 |
Chi-square | 0.000000 | 0.328307 | 181.674 | 80.1494 |
Intersection | 1.000000 | 0.75005 | 0.315061 | 0.0908022 |
Bhattacharyya | 0.000000 | 0.237866 | 0.679825 | 0.873709 |
Chi-Square alt. | 0.000000 | 0.395046 | 2.31572 | 3.41024 |
KL divergence | 0.000000 | 0.321064 | 2.6616 | 9.55412 |
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 four metrics, the less the result, the better the match.