# apply_colormap

Python API: `depthai_nodes.node.apply_colormap`

## Classes

### ApplyColormap

A host node that applies a colormap to a 2D array (e.g. depth maps, segmentation masks, heatmaps, etc.).

This node is generic and uses per-frame max-value normalization. For depth visualization prefer 'ApplyDepthColormap' to avoid
flicker caused by the changing normalization range.

Inputs:

 * `frame : dai.ImgFrame | dai.beta.Map2D | dai.ImgDetections | dai.SegmentationMask`: Input message containing a 2D array to be
   colorized.

Outputs:

 * `output : dai.ImgFrame`: Colorized output frame (3-channel BGR).

Parameters

 * `colormapValue`: OpenCV colormap enum (e.g. cv2.COLORMAP_JET) or a custom OpenCV-compatible colormap LUT. Default is
   cv2.COLORMAP_JET.
 * `maxValue`: Maximum value used for normalization. If set to 0, the maximum value is determined per-frame. Default is 0.

#### Methods

##### init

```python
def __init__(colormapValue: int | np.ndarray = cv2.COLORMAP_JET, maxValue: int = 0):
```

Initialize the image-processing node.

Parameters

 * `colormapValue` (`int | np.ndarray`): OpenCV colormap enum (e.g. cv2.COLORMAP_JET) or a custom OpenCV-compatible colormap LUT.
   Default is cv2.COLORMAP_JET.
 * `maxValue` (`int`): Maximum value used for normalization. If set to 0, the maximum value is determined per-frame. Default is 0.

##### build

```python
def build(frame: dai.Node.Output) -> ApplyColormap:
```

Connect the input stream to the node.

Parameters

 * `frame` (`dai.Node.Output`): Upstream output producing the map-like message to colorize.

Returns

 * `ApplyColormap`: The configured node instance.

##### process

```python
def process(frame: dai.Buffer):
```

Colorize a numeric map and emit an image with source metadata.

Parameters

 * `frame` (`dai.Buffer`): RAW ImgFrame, beta Map2D, SegmentationMask, or ImgDetections with an instance mask. Mask label 255 is
   background.

Raises

 * `TypeError`: If an ImgFrame does not use a RAW pixel format.
 * `ValueError`: If the message type is unsupported.

##### setColormap

```python
def setColormap(colormapValue: int | np.ndarray):
```

Set the color mapping applied to incoming maps.

Parameters

 * `colormapValue` (`int | np.ndarray`): OpenCV colormap enum value or a custom OpenCV-compatible LUT.

Raises

 * `ValueError`: If a custom colormap is not a uint8 array of shape `(256, 1, 3)`.

##### setMaxValue

```python
def setMaxValue(maxValue: int):
```

Set the normalization ceiling used during colorization.

Parameters

 * `maxValue` (`int`): Maximum input value used for normalization. 0 keeps per-frame normalization.

Raises

 * `ValueError`: If the ceiling is not a non-negative integer.
