Skip to content

Image Utilities

Reference information for the multimodal image utilities API.

eva.multimodal.utils.image.encode_image

Encodes an image tensor into a string format.

Parameters:

Name Type Description Default
image Image

The image tensor to encode.

required
encoding Literal['base64']

The encoding format to use. Currently only supports "base64".

required
**kwargs

Additional keyword arguments to pass to the encoding function.

{}

Returns:

Type Description
str

An encoded string representation of the image.

Source code in src/eva/multimodal/utils/image/encode.py
def encode_image(image: tv_tensors.Image, encoding: Literal["base64"], **kwargs) -> str:
    """Encodes an image tensor into a string format.

    Args:
        image: The image tensor to encode.
        encoding: The encoding format to use. Currently only supports "base64".
        **kwargs: Additional keyword arguments to pass to the encoding function.

    Returns:
        An encoded string representation of the image.
    """
    match encoding:
        case "base64":
            return _encode_base64(image, **kwargs)
        case _:
            raise ValueError(f"Unsupported encoding type: {encoding}. Supported: 'base64'")