mindspore.dataset.vision.ConvertColor
- class mindspore.dataset.vision.ConvertColor(convert_mode)[source]
Change the color space of the image.
- Parameters
convert_mode (ConvertMode) –
The mode of image channel conversion.
ConvertMode.COLOR_BGR2BGRA, Convert BGR image to BGRA image.
ConvertMode.COLOR_RGB2RGBA, Convert RGB image to RGBA image.
ConvertMode.COLOR_BGRA2BGR, Convert BGRA image to BGR image.
ConvertMode.COLOR_RGBA2RGB, Convert RGBA image 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
mindspore.dataset.vision.ConvertMode
.RuntimeError – If given tensor shape is not <H, W> or <H, W, C>.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> >>> # Convert RGB images to GRAY images >>> convert_op = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2GRAY) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=convert_op, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 100) uint8 >>> # Convert RGB images to BGR images >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> convert_op = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2BGR) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=convert_op, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 100, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3)) >>> output = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2GRAY)(data) >>> print(output.shape, output.dtype) (2, 2) uint8
- Tutorial Examples: