mindspore.dataset.vision.AutoContrast

View Source On AtomGit
class mindspore.dataset.vision.AutoContrast(cutoff=0.0, ignore=None)[source]

Automatically adjusts the contrast on the input image. This operation calculates the histogram of the image, reassigns cutoff percent of the lightest pixels from the histogram to 255, and reassigns cutoff percent of the darkest pixels from the histogram to 0.

Supports Ascend hardware acceleration and can be enabled through the .device("Ascend") method.

Parameters
  • cutoff (float, optional) – Percent of lightest and darkest pixels to cut off from the histogram of input image. The value must be in the range [0.0, 50.0]. Default: 0.0.

  • ignore (Union[int, sequence], optional) – The background pixel values to ignore. The ignore values must be in the range [0, 255]. Default: None.

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

  • TypeError – If ignore is not of type int or sequence.

  • ValueError – If cutoff is not in the range [0.0, 50.0).

  • ValueError – If ignore is not in the range [0, 255].

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

Supported Platforms:

CPU 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"])
>>> transforms_list = [vision.AutoContrast(cutoff=10.0, ignore=[10, 20])]
>>> 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.AutoContrast(cutoff=10.0, ignore=[10, 20])(data)
>>> print(output.shape, output.dtype)
(2, 2, 3) uint8
Tutorial Examples:
device(device_target='CPU')[source]

Set the device for the current operator execution.

When the device is Ascend, input type supports uint8 or float32 , input channel supports 1 and 3. If the data type is float32, the expected input value is in the range [0, 1]. The input data has a height limit of [4, 8192] and a width limit of [6, 4096].

Parameters

device_target (str, optional) – The operator will be executed on this device. Currently supports "CPU" and "Ascend" . Default: "CPU" .

Raises
  • TypeError – If device_target is not of type str.

  • ValueError – If device_target is not within the valid set of ["CPU", "Ascend"].

Supported Platforms:

CPU 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"])
>>> transforms_list = [vision.AutoContrast(cutoff=10.0, ignore=[10, 20]).device("Ascend")]
>>> 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.AutoContrast(cutoff=10.0, ignore=[10, 20]).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: