Clahe_equalized in 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

iam tryong to apply Contrast-limited adaptive histogram equalization (CLAHE) to my dataset but i am gitting just blank image
image

while the image should look like this

Then, write a Dataset class, and in my getitem function call that function for CLAHE

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()
        
1 Like