OpenCV 4.10.0-dev
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:
\[d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\]
where\[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\]
and \(N\) is the total number of histogram bins.\[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\]
\[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\]
\[d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\]
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 4 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.
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 |