我正在尝试使用 openCV 计算 HSV 图像的直方图,代码如下:
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
问题是,由于图像是 png,当我将它们转换为 HSV 时,我有很多黑色像素(曾经是透明背景)。但我不想在直方图中计算黑色像素,我该怎么办?
HSV 图像示例:
它看起来像 RGBA 格式的原始图像。使用图像的 Alpha 通道作为遮罩。