Grayscale

class paddle.vision.transforms. Grayscale ( num_output_channels=1, keys=None ) [source]

Converts image to grayscale.

Parameters
  • num_output_channels (int) – (1 or 3) number of channels desired for output image

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Returns

Grayscale version of the input. - If output_channels == 1 : returned image is single channel - If output_channels == 3 : returned image is 3 channel with r == g == b

Return type

CV Image

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)