# segmentation

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

## Functions

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

Parameters

 * `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.
 * `classes_in_one_layer` (`bool`): Whether a single channel already encodes class IDs rather than foreground scores.
 * `background_class` (`bool`): Replace winning class 0 with 255 for multi-class score tensors.

Returns

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

 * `ValueError`: If the unbatched tensor is not 3D or the resulting values are outside [0, 255].
