Grayscale¶
- class paddle.vision.transforms. Grayscale ( num_output_channels=1, keys=None ) [source]
-
Converts image to grayscale.
- Parameters
-
num_output_channels (int, optional) – (1 or 3) number of channels desired for output image. Default: 1.
keys (list[str]|tuple[str], optional) – Same as
BaseTransform
. Default: None.
- Shape:
-
img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
-
- output(PIL.Image|np.ndarray|Paddle.Tensor): Grayscale version of the input image.
-
If output_channels == 1 : returned image is single channel
If output_channels == 3 : returned image is 3 channel with r == g == b
- Returns
-
A callable object of Grayscale.
Examples
>>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import Grayscale >>> transform = Grayscale() >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) >>> fake_img = transform(fake_img) >>> print(np.array(fake_img).shape) (224, 224)