mindspore.dataset.vision.RandomPosterize
- class mindspore.dataset.vision.RandomPosterize(bits=(8, 8))[source]
- Reduce the bit depth of the color channels of image with a given probability to create a high contrast and vivid color image. - Reduce the number of bits for each color channel to posterize the input image randomly with a given probability. - Parameters
- bits (Union[int, Sequence[int]], optional) – Range of random posterize to compress image. Bits values must be in range of [1,8], and include at least one integer value in the given range. It must be in (min, max) or integer format. If min=max, then it is a single fixed magnitude operation. Default: - (8, 8).
- Raises
- TypeError – If bits is not of type integer or sequence of integer. 
- ValueError – If bits is not in range [1, 8]. 
- 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.RandomPosterize((6, 8))] >>> 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.RandomPosterize(1)(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8 - Tutorial Examples: