# LeapImageMask

Used to visualize a semantic segmentation mask

```python
import numpy.typing as npt
from code_loader.contract.enums import LeapDataType

@dataclass
class LeapImageMask:
    mask: npt.NDArray[np.uint8]
    image: npt.NDArray[np.float32]
    labels: List[str]
    type: LeapDataType = LeapDataType.ImageMask
```

<table><thead><tr><th width="167.39065467110788">Args</th><th></th></tr></thead><tbody><tr><td><code>image</code></td><td>np.ndarray uint8/float32 representation of the image. The expected image format is [H,W,1] OR [H,W,3] and is expected to be in [0,255].</td></tr><tr><td><code>mask</code></td><td>np.ndarray uint8 representation of the mask. The expected format is [H,W] where each pixel value signifies its label</td></tr><tr><td><code>labels</code></td><td>A list of strings mapping pixel values to their labels</td></tr></tbody></table>

## Examples

#### Basic Usage

```python
import numpy as np
from code_loader.contract.visualizer_classes import LeapImageMask
from code_loader import leap_binder
from code_loader.contract.enums import LeapDataType
...

@tensorleap_custom_visualizer(name='seg_visualizer',
                              visualizer_type=LeapDataType.ImageMask,
                              heatmap_function=None)
def segmentation_visualizer(image: np.ndarray, segmentation_prediction: np.ndarray) -> LeapImageMask:
    labels = ['background', 'vehicle', 'tree', 'road', 'pavement']
    return LeapImageMask(mask=segmentation_prediction.squeeze(0), image=image.squeeze(0), labels=labels)
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
