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.
- 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: