Image
Inherits from:object
A class to represent an image
Attributes:
data (Union[np.ndarray, bytes]): image data (H x W x C) or raw bytes
capture_params (dict, optional): the parameters of image capture
img_type (str): type of the image (‘rgb’, ‘depth’, ‘segmentation’)
shape (tuple, optional): Shape for bytes data (height, width, channels)
dtype (np.dtype, optional): Data type for bytes data
init
Arguments
Image data as a numpy array with shape (H, W, C) where: - H: Height in pixels - W: Width in pixels - C: Number of channels (e.g., 3 for RGB, 1 for grayscale) The array should have dtype uint8 for standard images, but other dtypes are supported (float32, uint16, etc.)
Dictionary containing metadata about how the image was captured. Can include camera parameters, timestamps, exposure settings, etc. Defaults to None.
Type/format of the image. Common values include: - ‘rgb’: Standard RGB color image - ‘depth’: Depth map image - ‘segmentation’: Semantic segmentation mask - ‘grayscale’: Single channel grayscale image Defaults to None.
init
Arguments
Raw image data in bytes format. This should be the flattened pixel data without any headers or metadata. The total number of bytes should match: height × width × channels × bytes_per_pixel
Shape of the image as (height, width, channels). For example: - (480, 640, 3): 480x640 RGB image - (720, 1280, 1): 720x1280 grayscale image - (1080, 1920, 4): 1080x1920 RGBA image
Data type of the pixel values. Common types include: - np.uint8: Standard 8-bit images (0-255 range) - np.uint16: 16-bit images (0-65535 range, common for depth) - np.float32: Floating point images (often normalized 0.0-1.0) - np.int16: Signed 16-bit (sometimes used for depth with negative values)
Dictionary containing metadata about how the image was captured. Defaults to None.
Type/format of the image (‘rgb’, ‘depth’, ‘segmentation’, etc.). Defaults to None.
Raises
ValueError
If the provided bytes data is too small for the specified shape and dtype combination.
Note
This method is optimized for speed and memory efficiency. It uses np.frombuffer() for fast conversion and only processes the last expected_size bytes if the data is larger than needed. This allows handling of data with headers or padding.
init
Arguments
No description provided.
No description provided.
No description provided.
No description provided.
No description provided.