> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapimagewithbbox.md).

# LeapImageWithBBox

code\_loader.contract.visualizer\_classes.LeapImageWithBBox

Used to visualize an image with bounding boxes drawn over it.

```python
@dataclass
class BoundingBox:
    x: float
    y: float
    width: float
    height: float
    confidence: float
    label: str
    rotation: float = 0.0
    metadata: Optional[Dict[str, Union[str, int, float]]] = None

@dataclass
class LeapImageWithBBox:
    data: Union[npt.NDArray[np.float32], npt.NDArray[np.uint8]]
    bounding_boxes: List[BoundingBox]
    type: LeapDataType = LeapDataType.ImageWithBBox
```

| Args             |                                                                                                                                                                                                                                                 |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`           | `np.ndarray` of dtype `uint8` or `float32`, shape `[H, W, 1]` or `[H, W, 3]`. Pixel values must be in `[0, 255]`, as for [LeapImage](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapimage.md). |
| `bounding_boxes` | A list of `BoundingBox` objects (from `code_loader.contract.responsedataclasses`), described below.                                                                                                                                             |

**BoundingBox** fields:

* `x`, `y`: the center of the box, as a fraction of the image width and height, in `[0, 1]`.
* `width`, `height`: the size of the box, as a fraction of the image width and height, in `[0, 1]`.
* `confidence`: the prediction's score, usually in `[0, 1]`. Use `1` for ground truth.
* `label`: the class name.
* `rotation` *(optional)*: rotation in degrees, in `[0, 360]`. Defaults to `0`.
* `metadata` *(optional)*: extra properties of the box, as a dictionary from name to `str`, `int` or `float`.

## Examples

#### Basic Usage

```python
import numpy as np
from code_loader.contract.visualizer_classes import LeapImageWithBBox
from code_loader.contract.responsedataclasses import BoundingBox
from code_loader.contract.enums import LeapDataType
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_custom_visualizer


@tensorleap_custom_visualizer('bb_gt_visualizer', LeapDataType.ImageWithBBox)
def gt_bb_visualizer(image: np.ndarray, bb_gt: np.ndarray) -> LeapImageWithBBox:
    # bb_gt: [1, MAX_BOXES, 5] with rows [x, y, w, h, class_id]; padded rows hold NaN
    boxes = [
        BoundingBox(x=float(b[0]), y=float(b[1]), width=float(b[2]), height=float(b[3]),
                    confidence=1.0, label=CLASS_NAMES.get(int(b[4]), 'Unknown Class'))
        for b in bb_gt[0] if not np.isnan(b[4])
    ]
    return LeapImageWithBBox(data=image[0], bounding_boxes=boxes)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leapimagewithbbox.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
