mindspore.dataset.vision.Grayscale

class mindspore.dataset.vision.Grayscale(num_output_channels=1)[source]

Convert the input PIL Image to grayscale.

Parameters

num_output_channels (int) – The number of channels desired for the output image, must be 1 or 3. If 3 is provided, the returned image will have 3 identical RGB channels. Default: 1.

Raises
  • TypeError – If num_output_channels is not of type integer.

  • ValueError – If num_output_channels is not 1 or 3.

Supported Platforms:

CPU

Examples

>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.Grayscale(3),
...                            vision.ToTensor()])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")