mindspore.dataset.vision.encode_jpeg
- mindspore.dataset.vision.encode_jpeg(image, quality=75)[source]
Encode the input image as JPEG data.
- Parameters
image (Union[numpy.ndarray, mindspore.Tensor]) – The image to be encoded.
quality (int, optional) – Quality of the resulting JPEG data, in range of [1, 100]. Default: 75.
- Returns
numpy.ndarray, one dimension uint8 data.
- Raises
TypeError – If image is not of type numpy.ndarray or mindspore.Tensor.
TypeError – If quality 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 quality is less than 1 or greater than 100.
- 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) >>> jpeg_data = vision.encode_jpeg(image)