mindspore.dataset.vision.RandomGrayscale

class mindspore.dataset.vision.RandomGrayscale(prob=0.1)[source]

Randomly convert the input PIL Image to grayscale.

Parameters

prob (float, optional) – Probability of performing grayscale conversion. Default: 0.1.

Raises
  • TypeError – If prob is not of type float.

  • ValueError – If prob is not in range of [0, 1].

Supported Platforms:

CPU

Examples

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

Execute method.

Parameters

img (PIL Image) – Image to be randomly converted to grayscale.

Returns

PIL Image, randomly converted grayscale image, which has the same number of channels as the input image.

If input image has 1 channel, the output grayscale image will have 1 channel. If input image has 3 channels, the output grayscale image will have 3 identical channels.