PNG Process
pngencode
pngencode(img: np.ndarray, compression: int = 1) -> Union[bytes, None]
-
Description: Encodes a NumPy image array into a PNG format byte string.
-
Parameters:
- img (
np.ndarray
): The image array to encode. - compression (
int
): The compression level, ranging from 0 to 9. 0 means no compression, and 9 represents maximum compression. Default is 1.
- img (
-
Return value:
- bytes: The PNG format byte string after encoding.
-
Example:
import numpy as np
import capybara as cb
img_array = np.random.rand(100, 100, 3) * 255
encoded_bytes = cb.pngencode(img_array, compression=9)
pngdecode
-
Description: Decodes a PNG format byte string into a NumPy image array.
-
Parameters:
- byte_ (
bytes
): The PNG format byte string to decode.
- byte_ (
-
Return value:
- np.ndarray: The image array after decoding.
-
Example:
decoded_img = cb.pngdecode(encoded_bytes)