Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

compareHist with HISTCMP_CORREL

I'm evaluating compareHist() and when I compare a 'flat' histogram with a single spike, the correlation value is 1.0! This is obviously wrong (by hand I get zero divided by zero but it should be approaching zero).

Am I doing something wrong? Here's my code:

import numpy, cv2

spike = numpy.ones((1,256), dtype=numpy.uint8).reshape(16, 16) * 127
flat = numpy.arange(256, dtype=numpy.uint8).reshape(16,16)
# Calculate the histograms
hist_s = cv2.calcHist([spike], [0], None, [256], [0, 256])
hist_f = cv2.calcHist([flat], [0], None, [256], [0, 256])
print cv2.compareHist(hist_f, hist_s, method=0)

returns 1.0

Plot of the two histograms (spike=red, flat=blue):

image description