我正在尝试将对比度受限的自适应直方图均衡化(CLAHE)应用于我在pytorch中的自定义数据集加载器,但是我只是搅拌空白图像 我定义的功能如下
def clahe_equalized(imgs):
len(imgs.shape)==4 #4D arrays
imgs.shape[1]==1 #check the channel is 1
#create a CLAHE object (Arguments are optional).
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
imgs_equalized = np.empty(imgs.shape)
for i in range(imgs.shape[0]):
imgs_equalized[i,0] = clahe.apply(np.array(imgs[i,0], dtype = np.uint8))
return imgs_equalized
调用该函数
def __getitem__(self,idx):
"""Get specific data corresponding to the index
Args:
index (int): index of the data
Returns:
Tensor: specific data on index which is converted to Tensor
"""
"""
# GET IMAGE
"""
single_image_name = self.image_arr[idx]
img_as_img = Image.open(os.path.join(self.image_path,single_image_name))
plt.title('or')
plt.imshow(img_as_img)
plt.show()
img_as_np = np.asarray(img_as_img)
mg_as_img = Image.fromarray(img_as_np)
img_as_img = img_as_img.convert('L')
plt.title('gray scal')
img_as_np = np.asarray(img_as_img)
plt.imshow(img_as_img)
plt.show()
img_as_np = clahe_equalized(img_as_np)
plt.imshow(img_as_np)
plt.show()
正确的图片应该像这样enter image description here