mindspore.dataset.vision.encode_png

mindspore.dataset.vision.encode_png(image, compression_level=6)[source]

Encode the input image as PNG data.

Parameters
  • image (Union[numpy.ndarray, mindspore.Tensor]) – The image to be encoded.

  • compression_level (int, optional) – The compression_level for encoding, in range of [0, 9]. Default: 6.

Returns

numpy.ndarray, one dimension uint8 data.

Raises
  • TypeError – If image is not of type numpy.ndarray or mindspore.Tensor.

  • TypeError – If compression_level is not of type int.

  • RuntimeError – If the data type of image is not uint8.

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

  • RuntimeError – If compression_level is less than 0 or greater than 9.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> # Generate a random image with height=120, width=340, channels=3
>>> image = np.random.randint(256, size=(120, 340, 3), dtype=np.uint8)
>>> png_data = vision.encode_png(image)