Skip to main content
A class to represent an image. img_type describes the semantic content of the image (“rgb”, “depth”, “segmentation”, …). encoding_format describes the wire encoding of data — empty string for a raw ndarray (or a raw pixel-buffer reshaped into one), or one of {“jpeg”, “png”, “webp”} when data is the encoded bytes from a camera firmware / image-transport plugin. The two are orthogonal: a JPEG is still semantically an RGB image after decoding.

Fields

Union[np.ndarray, bytes]
image data (H x W x C ndarray for raw, or the encoded byte blob when encoding_format is set).
dict, optional
the parameters of image capture.
str
semantic image type (“rgb”, “depth”, “segmentation”, …).
str
"" for raw pixel data; “jpeg” / “png” / “webp” when data is encoded bytes. Use Image.decode() to lazily turn encoded bytes into an ndarray.
tuple, optional
Shape for raw bytes data (height, width, channels).
np.dtype, optional
Data type for raw bytes data.

Constructor

Signature

Methods

decode()

Signature
Return an RGB ndarray, decoding from JPEG/PNG/WebP if needed. No-op (returns self.data) when the image is already an ndarray.

from_dict()

Signature
Deserialize from dictionary - handles encoded formats and the legacy ndarray + image_data variants.

to_dict()

Signature
Serialize to dictionary for JSON transfer. For encoded formats (JPEG/PNG/WebP) the bytes are kept as-is and flagged with encoding_format; the receiver reconstructs via from_dict without reshaping. For ndarrays we fall back to the legacy raw-bytes-with-shape/dtype path.

Example