MATLAB File Help: cv.compareHist | Index |
Compares two histograms
d = cv.compareHist(H1, H2)
d = cv.compareHist(H1, H2, 'Method', method)
H1
.d(H1,H2)
.The function compares two dense or two sparse histograms using the specified method.
While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms or more general sparse configurations of weighted points, consider using the cv.EMD function.
Histogram comparison methods:
Correlation Correlation.
d(H1,H2) = (sum{I}((H1(I) - H1hat(I))*(H2(I) - H2_hat(I)))) / (sum{I}(H1(I) - H1hat(I))^2 * sum{I}(H2(I) - H2hat(I))^2)
where Hk_hat = 1/N * sum_{J} Hk(J)
and N
is a total number of
histogram bins.
ChiSquare Chi-Square.
d(H1,H2) = sum_{I} ((H1(I) - H2(I))^2 / H1(I))
Intersection Intersection.
d(H1,H2) = sum_{I} min(H1(I), H2(I))
Bhattacharyya Bhattacharyya distance (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient).
d(H1,H2) = sqrt(1 - (1/sqrt(H1hat(I)*H2hat(I)*N^2)) * sum_{I}(sqrt(H1(I)*H2(I))))
Hellinger Synonym for 'Bhattacharyya'.
AltChiSquare Alternative Chi-Square.
d(H1,H2) = 2 * sum_{I} ((H1(I) - H2(I))^2 / (H1(I) + H2(I)))
This alternative formula is regularly used for texture comparison. See e.g. [Puzicha1997]
KullbackLeibler Kullback-Leibler divergence.
d(H1,H2) = sum_{I} (H1(I) * log(H1(I)/H2(I)))
[Puzicha1997]:
Jan Puzicha, Thomas Hofmann, and Joachim M Buhmann. "Non-parametric similarity measures for unsupervised texture segmentation and image retrieval". In Computer Vision and Pattern Recognition, 1997. Proceedings., 1997 IEEE Computer Society Conference on, pages 267-272.