mindspore.dataset.vision.c_transforms.ConvertColor

class mindspore.dataset.vision.c_transforms.ConvertColor(convert_mode)[source]

Change the color space of the image.

Parameters

convert_mode (ConvertMode) –

The mode of image channel conversion.

  • ConvertMode.COLOR_BGR2BGRA, Add alpha channel to BGR image.

  • ConvertMode.COLOR_RGB2RGBA, Add alpha channel to RGB image.

  • ConvertMode.COLOR_BGRA2BGR, Remove alpha channel to BGR image.

  • ConvertMode.COLOR_RGBA2RGB, Remove alpha channel to RGB image.

  • ConvertMode.COLOR_BGR2RGBA, Convert BGR image to RGBA image.

  • ConvertMode.COLOR_RGB2BGRA, Convert RGB image to BGRA image.

  • ConvertMode.COLOR_RGBA2BGR, Convert RGBA image to BGR image.

  • ConvertMode.COLOR_BGRA2RGB, Convert BGRA image to RGB image.

  • ConvertMode.COLOR_BGR2RGB, Convert BGR image to RGB image.

  • ConvertMode.COLOR_RGB2BGR, Convert RGB image to BGR image.

  • ConvertMode.COLOR_BGRA2RGBA, Convert BGRA image to RGBA image.

  • ConvertMode.COLOR_RGBA2BGRA, Convert RGBA image to BGRA image.

  • ConvertMode.COLOR_BGR2GRAY, Convert BGR image to GRAY image.

  • ConvertMode.COLOR_RGB2GRAY, Convert RGB image to GRAY image.

  • ConvertMode.COLOR_GRAY2BGR, Convert GRAY image to BGR image.

  • ConvertMode.COLOR_GRAY2RGB, Convert GRAY image to RGB image.

  • ConvertMode.COLOR_GRAY2BGRA, Convert GRAY image to BGRA image.

  • ConvertMode.COLOR_GRAY2RGBA, Convert GRAY image to RGBA image.

  • ConvertMode.COLOR_BGRA2GRAY, Convert BGRA image to GRAY image.

  • ConvertMode.COLOR_RGBA2GRAY, Convert RGBA image to GRAY image.

Raises
  • TypeError – If convert_mode is not of type ConvertMode.

  • RuntimeError – If given tensor shape is not <H, W> or <H, W, C>.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset.vision.utils as mode
>>> # Convert RGB images to GRAY images
>>> convert_op = c_vision.ConvertColor(mode.ConvertMode.COLOR_RGB2GRAY)
>>> image_folder_dataset = image_folder_dataset.map(operations=convert_op,
...                                                 input_columns=["image"])
>>> # Convert RGB images to BGR images
>>> convert_op = c_vision.ConvertColor(mode.ConvertMode.COLOR_RGB2BGR)
>>> image_folder_dataset_1 = image_folder_dataset_1.map(operations=convert_op,
...                                                     input_columns=["image"])