> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Image

## 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**

```python theme={null}
Image.__init__(data: np.ndarray, capture_params: Optional[dict] = None, img_type: Optional[str] = None) -> None
```

Initialize an Image from a numpy array.

This is the most common way to create an Image object when you already have
image data as a numpy array. The array should be in HWC format (Height, Width, Channels).

<ResponseField name="Arguments">
  <ParamField query="data (np.ndarray)" type="np.ndarray" required>
    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.)
  </ParamField>

  <ParamField query="capture_params (Optional[dict])" type="Optional[dict]">
    Dictionary containing metadata about how the image was captured. Can include camera parameters, timestamps, exposure settings, etc. Defaults to None.
  </ParamField>

  <ParamField query="img_type (Optional[str])" type="Optional[str]">
    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.
  </ParamField>
</ResponseField>

<ResponseField name="Returns">
  <ResponseField name="returns" type="None" />
</ResponseField>

### **init**

```python theme={null}
Image.__init__(data: bytes, shape: tuple, dtype: np.dtype, capture_params: Optional[dict] = None, img_type: Optional[str] = None) -> None
```

Initialize an Image from raw bytes data.

This method is optimized for performance when receiving image data as raw bytes
from cameras, network streams, or file I/O. The bytes are efficiently converted
to a numpy array using the provided shape and dtype information.

<ResponseField name="Arguments">
  <ParamField query="data (bytes)" type="bytes" required>
    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
  </ParamField>

  <ParamField query="shape (tuple)" type="tuple" required>
    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
  </ParamField>

  <ParamField query="dtype (np.dtype)" type="np.dtype" required>
    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)
  </ParamField>

  <ParamField query="capture_params (Optional[dict])" type="Optional[dict]">
    Dictionary containing metadata about how the image was captured. Defaults to None.
  </ParamField>

  <ParamField query="img_type (Optional[str])" type="Optional[str]">
    Type/format of the image ('rgb', 'depth', 'segmentation', etc.). Defaults to None.
  </ParamField>
</ResponseField>

<ResponseField name="Returns">
  <ResponseField name="returns" type="None" />
</ResponseField>

<ResponseField name="Raises">
  <ParamField query="ValueError" type="">
    If the provided bytes data is too small for the specified shape and dtype combination.
  </ParamField>

  <ParamField query="Note" type="">
    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.
  </ParamField>
</ResponseField>

### **init**

```python theme={null}
Image.__init__(data: Union[np.ndarray, bytes], shape: Optional[tuple] = None, dtype: Optional[np.dtype] = None, capture_params: Optional[dict] = None, img_type: Optional[str] = None)
```

*No docstring provided.*

<ResponseField name="Arguments">
  <ParamField query="data (Union[np.ndarray, bytes])" type="Union[np.ndarray, bytes]" required>
    *No description provided.*
  </ParamField>

  <ParamField query="shape (Optional[tuple])" type="Optional[tuple]">
    *No description provided.*
  </ParamField>

  <ParamField query="dtype (Optional[np.dtype])" type="Optional[np.dtype]">
    *No description provided.*
  </ParamField>

  <ParamField query="capture_params (Optional[dict])" type="Optional[dict]">
    *No description provided.*
  </ParamField>

  <ParamField query="img_type (Optional[str])" type="Optional[str]">
    *No description provided.*
  </ParamField>
</ResponseField>

### to\_dict

```python theme={null}
Image.to_dict() -> dict
```

Serialize to dictionary for JSON transfer

<ResponseField name="Returns">
  <ResponseField name="returns" type="dict" />
</ResponseField>

### from\_dict

```python theme={null}
Image.from_dict(data: dict) -> 'Image'
```

Deserialize from dictionary - handles both old and new encoded formats

<ResponseField name="Arguments">
  <ParamField query="data (dict)" type="dict" required>
    *No description provided.*
  </ParamField>
</ResponseField>

<ResponseField name="Returns">
  <ResponseField name="returns" type="'Image'" />
</ResponseField>
