mindspore.dataset.vision.Grayscale

class mindspore.dataset.vision.Grayscale(num_output_channels=1)[源代码]

将输入PIL图像转换为灰度图。

参数:
  • num_output_channels (int) - 输出灰度图的通道数,取值可为 13 。当取值为 3 时,返回图像各通道的像素值将相同。默认值: 1

异常:
  • TypeError - 当 num_output_channels 的类型不为int。

  • ValueError - 当 num_output_channels 取值不为 13

支持平台:

CPU

样例:

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> 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 = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
教程样例: