mindspore.dataset.vision.AdjustGamma

View Source On Gitee
class mindspore.dataset.vision.AdjustGamma(gamma, gain=1)[source]

Apply gamma correction on input image. Input image is expected to be in <…, H, W, C> or <H, W> format.

Iout=255×gain×(Iin255)γ

See Gamma Correction for more details.

Parameters
  • gamma (float) – Non negative real number. The output image pixel value is exponentially related to the input image pixel value. gamma larger than 1.0 make the shadows darker, while gamma smaller than 1.0 make dark regions lighter.

  • gain (float, optional) – The constant multiplier. Default: 1.0.

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

  • TypeError – If gamma is not of type float.

  • ValueError – If gamma is less than 0.0.

  • 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"])
>>> transforms_list = [vision.AdjustGamma(gamma=10.0, gain=1.0)]
>>> 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.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
>>> output = vision.AdjustGamma(gamma=0.1, gain=1.0)(data)
>>> print(output.shape, output.dtype)
(2, 2, 3) uint8
Tutorial Examples: