I'm trying to compute the histogram of an HSV image with openCV, with the following code:
def istogrammaHSV(image,histSize):
hsv_planes= cv2.split(image)
histSize= histSize
histRange= (0,256)
accumulate=False
h_hist = np.array(cv2.calcHist(hsv_planes, [0], None, [histSize], histRange, accumulate=accumulate),dtype='uint8' )
s_hist = np.array(cv2.calcHist(hsv_planes, [1], None, [histSize], histRange, accumulate=accumulate),dtype='uint8' )
v_hist = np.array(cv2.calcHist(hsv_planes, [2], None, [histSize], histRange, accumulate=accumulate),dtype='uint8' )
#normalization
hist = np.append(h_hist, s_hist, axis=0)
hist = np.append(hist, v_hist, axis=0)
hist = hist / np.sqrt(np.sum(hist**2))
return hist
The problem is that, since the images are png, when i convert them to HSV i have a lot of black pixels (what once was the transparent background). But i don't want the black pixels to be computed in the histogram, what can i do?
Sample HSV image: