mindspore.dataset.vision.RandomColorAdjust
- class mindspore.dataset.vision.RandomColorAdjust(brightness=(1, 1), contrast=(1, 1), saturation=(1, 1), hue=(0, 0))[source]
Randomly adjust the brightness, contrast, saturation, and hue of the input image.
Note
This operation is executed on the CPU by default, but it is also supported to be executed on the GPU or Ascend via heterogeneous acceleration.
- Parameters
brightness (Union[float, Sequence[float]], optional) – Brightness adjustment factor. Default:
(1, 1)
. Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-brightness), 1+brightness]. If it is a sequence, it should be [min, max] for the range.contrast (Union[float, Sequence[float]], optional) – Contrast adjustment factor. Default:
(1, 1)
. Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-contrast), 1+contrast]. If it is a sequence, it should be [min, max] for the range.saturation (Union[float, Sequence[float]], optional) – Saturation adjustment factor. Default:
(1, 1)
. Cannot be negative. If it is a float, the factor is uniformly chosen from the range [max(0, 1-saturation), 1+saturation]. If it is a sequence, it should be [min, max] for the range.hue (Union[float, Sequence[float]], optional) – Hue adjustment factor. Default:
(0, 0)
. If it is a float, the range will be [-hue, hue]. Value should be 0 <= hue <= 0.5. If it is a sequence, it should be [min, max] where -0.5 <= min <= max <= 0.5.
- Raises
TypeError – If brightness is not of type float or Sequence[float].
TypeError – If contrast is not of type float or Sequence[float].
TypeError – If saturation is not of type float or Sequence[float].
TypeError – If hue is not of type float or Sequence[float].
ValueError – If brightness is negative.
ValueError – If contrast is negative.
ValueError – If saturation is negative.
ValueError – If hue is not in range [-0.5, 0.5].
RuntimeError – If given tensor shape is not <H, W, C>.
- Supported Platforms:
CPU
GPU
Ascend
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"]) >>> transform_op = vision.RandomColorAdjust(brightness=(0.5, 1), ... contrast=(0.4, 1), ... saturation=(0.3, 1)) >>> transforms_list = [transform_op] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, 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.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.RandomColorAdjust(brightness=(0.5, 1), contrast=(0.4, 1), saturation=(0.3, 1))(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8
- Tutorial Examples: