to_grayscale¶
- paddle.vision.transforms. to_grayscale ( img, num_output_channels=1 ) [source]
- 
         Converts image to grayscale version of image. - Parameters
- 
           img (PIL.Image|np.array) – Image to be converted to grayscale. 
- Returns
- 
           
           - Grayscale version of the image.
- 
             if num_output_channels = 1 : returned image is single channel if num_output_channels = 3 : returned image is 3 channel with r = g = b 
 
- Return type
- 
           PIL.Image or np.array 
 Examples import numpy as np from PIL import Image from paddle.vision.transforms import functional as F fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') fake_img = Image.fromarray(fake_img) gray_img = F.to_grayscale(fake_img) print(gray_img.size) 
