compareHist with HISTCMP_CORREL

asked 2015-08-19 18:34:15 -0500

Gnimbus gravatar image

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

edit retag flag offensive close merge delete