mindspore.dataset.vision.write_png

View Source On Gitee
mindspore.dataset.vision.write_png(filename, image, compression_level=6)[source]

Write the image into a PNG file.

Parameters
  • filename (str) – The path to the file to be written.

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

  • compression_level (int, optional) – Compression level for the resulting PNG file, in range of [0, 9]. Default: 6.

Raises
  • TypeError – If filename is not of type str.

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

  • TypeError – If compression_level is not of type int.

  • RuntimeError – If the filename does not exist or not a common file.

  • 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 mindspore.dataset.vision as vision
>>> 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)
>>> vision.write_png("/path/to/file", image)