mindspore.dataset.vision.Solarize

View Source On Gitee
class mindspore.dataset.vision.Solarize(threshold)[source]

Solarize the image by inverting all pixel values within the threshold.

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

Parameters

threshold (Union[float, Sequence[float, float]]) – Range of solarize threshold, should always be in (min, max) format, where min and max are integers in range of [0, 255], and min <= max. The pixel values belonging to the [min, max] range will be inverted. If a single value is provided or min=max, then invert all pixel values greater than or equal min(max).

Raises
  • TypeError – If threshold is not of type float or Sequence[float, float].

  • ValueError – If threshold is not in range of [0, 255].

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.Solarize(threshold=(10, 100))]
>>> 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.Solarize(threshold=(1, 10))(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples:
device(device_target='CPU')[source]

Set the device for the current operator execution.

  • When the device is Ascend, input type only supports uint8 , input channel supports 1 and 3. 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"])
>>> solarize_op = vision.Solarize(threshold=(10, 100)).device("Ascend")
>>> transforms_list = [solarize_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.Solarize(threshold=(10, 100)).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: