imencode
imencode(img: np.ndarray, IMGTYP: Union[str, int, IMGTYP] = IMGTYP.JPEG) -> Union[bytes, None]
-
Description: Encodes a NumPy image array into a byte string in a specified format.
-
Parameters:
- img (
np.ndarray
): The image array to encode. - IMGTYP (
Union[str, int, IMGTYP]
): The image type. Supported types areIMGTYP.JPEG
andIMGTYP.PNG
. Default isIMGTYP.JPEG
.
- img (
-
Return value:
- bytes: The encoded image byte string.
-
Example:
import capybara as cb
img = cb.imread('lena.png')
encoded_bytes = cb.imencode(img, IMGTYP=cb.IMGTYP.PNG)