1
我试图如下Python的OpenCV的规格化具有零均值和单位方差
out_image = np.zeros((32,32),dtype=np.float32)
out_array = np.zeros((len(X),32,32), dtype=np.uint8)
for imageindex in range(0,len(X)):
img = X[imageindex].squeeze()
if proctype == 'MeanSubtraction':
out_image = img.astype(np.float32) - np.mean(img.astype(np.float32))
elif proctype == 'Normalization':
out_image = cv2.normalize(img.astype(np.float32), out_image, alpha=-0.5, beta=0.5,\
norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
elif proctype == 'HistEqualization':
out_image = cv2.equalizeHist(img)
elif proctype == 'CLAHE':
clahe = cv2.createCLAHE(tileGridSize=(6,6),clipLimit = 20.0)
out_image = clahe.apply(img)
out_array[imageindex] = out_image.astype(np.uint8)
return out_array
然而正常化灰度图像具有零均值和单位方差与cv2.normalize功能的数组,如果使用0和1(或0和255)用于归一化函数的参数alpha和beta,它可以工作。但是如果我使用-0.5和+0.5,它会给我一个空的图像(全零)
为什么会发生这种情况?
是的。我将out_array的dtype更改为np.float32,现在可以工作了。谢谢 – Mechanic