# segmentation

Python API: `depthai_nodes.node.parsers.utils.segmentation`

## Functions

| Name | Description |
| --- | --- |
| [`compute_segmentation_class_map`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/segmentation.md#segmentation-Functions-compute_segmentation_class_map) | Convert segmentation scores or encoded labels into a uint8 class map. |

### function `compute_segmentation_class_map`

```python
def compute_segmentation_class_map(
    segmentation_mask: np.ndarray,
    *,
    classes_in_one_layer: bool = False,
    background_class: bool = False,
) -> np.ndarray
```

Convert segmentation scores or encoded labels into a uint8 class map.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `segmentation_mask` | `np.ndarray` | CHW or HWC tensor, optionally batched. A 4D tensor uses its first batch item; the smallest axis is treated as the class axis. | required |
| `classes_in_one_layer` | `bool` | Whether a single channel already encodes class IDs rather than foreground scores. | `False` |
| `background_class` | `bool` | Replace winning class 0 with 255 for multi-class score tensors. | `False` |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | An HW uint8 label map. Unassigned pixels are 255. A single foreground-score channel is compared against zero and emits class 0 for positive pixels. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the unbatched tensor is not 3D or the resulting values are outside [0, 255]. |
