mindspore.dataset.vision.Posterize

class mindspore.dataset.vision.Posterize(bits)[source]

Reduce the bit depth of the color channels of image to create a high contrast and vivid color effect, similar to that seen in posters or printed materials.

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

Parameters

bits (int) – The number of bits to keep for each channel, should be in range of [0, 8].

Raises
  • TypeError – If bits is not of type int.

  • ValueError – If bits is not in range [0, 8].

  • RuntimeError – If shape of the input image is not <H, W> or <H, W, C>.

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.Posterize(4)]
>>> 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.Posterize(4)(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 supports uint8/float32, 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"])
>>> posterize_op = vision.Posterize(4).device("Ascend")
>>> transforms_list = [posterize_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.Posterize(4).device("Ascend")(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: