一开始的用PIL读取了图片,先转变成cv2,然后三通道变三个单通道
#------------------------------#
# createCLAHE直方图均值
#------------------------------#
image_data = cv2.cvtColor(np.array(image,,np.float32),cv2.COLOR_RGB2BGR)
# print(image_data.shape)
imgr = image_data[:,:,0]
imgg = image_data[:,:,1]
imgb = image_data[:,:,2]
# print(imgr.shape)
clahe = cv2.createCLAHE(clipLimit=2, tileGridSize=(8,8))
cllr = clahe.apply(imgr)
cllg = clahe.apply(imgg)
cllb = clahe.apply(imgb)
image_data = np.dstack((cllr,cllg,cllb))
结果仍就报错error: (-215:Assertion failed) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function ‘`anonymous- namespace’::CLAHE_Impl::apply’
然后改成了
#------------------------------#
# createCLAHE直方图均值
#------------------------------#
image_data = cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR)
# print(image_data.shape)
imgr = image_data[:,:,0]
imgg = image_data[:,:,1]
imgb = image_data[:,:,2]
# print(imgr.shape)
clahe = cv2.createCLAHE(clipLimit=2, tileGridSize=(8,8))
cllr = clahe.apply(imgr)
cllg = clahe.apply(imgg)
cllb = clahe.apply(imgb)
image_data = np.dstack((cllr,cllg,cllb))
然后就好了…可能和float有关,不懂
array和asarray都可以将结构数据转化为ndarray,但是主要区别就是当数据源是ndarray时,array仍然会copy出一个副本,占用新的内存,属于深拷贝。但asarray不会。