Exemple #1
0
    def __call__(self, img, target):
        """
        Args:
            img (PIL Image): Image to be converted to grayscale.

        Returns:
            PIL Image: Randomly grayscaled image.
        """
        return F.to_grayscale(img, num_output_channels=self.num_output_channels), F.to_grayscale(target, num_output_channels=self.num_output_channels)
Exemple #2
0
 def __call__(self, img):
     """
     Args:
         img (numpy ndarray): Image to be converted to grayscale.
     Returns:
         numpy ndarray: Randomly grayscaled image.
     """
     return F.to_grayscale(img,
                           num_output_channels=self.num_output_channels)
Exemple #3
0
 def __call__(self, img):
     """
     Args:
         img (PIL Image): Image to be converted to grayscale.
     Returns:
         PIL Image: Randomly grayscaled image.
     """
     num_output_channels = 1 if img.mode == 'L' else 3
     if random.random() < self.p:
         return F.to_grayscale(img, num_output_channels=num_output_channels)
     return img