# apply_colormap

Python API: `depthai_nodes.node.apply_colormap`

## Classes

| Name | Description |
| --- | --- |
| [`ApplyColormap`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap) | A host node that applies a colormap to a 2D array (e.g. depth maps, segmentation masks, heatmaps, etc.). |

### class `ApplyColormap`

```python
class ApplyColormap(BaseHostNode)
```

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

Args

| Name | Description |
| --- | --- |
| `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

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap-__init__) | Initialize the image-processing node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap-build) | Connect the input stream to the node. |
| [`process`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap-process) | Colorize a numeric map and emit an image with source metadata. |
| [`setColormap`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap-setColormap) | Set the color mapping applied to incoming maps. |
| [`setMaxValue`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/apply_colormap.md#apply_colormap-Classes-ApplyColormap-setMaxValue) | Set the normalization ceiling used during colorization. |

#### method `__init__`

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

Initialize the image-processing node.

Args

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

#### method `build`

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

Connect the input stream to the node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `frame` | `dai.Node.Output` | Upstream output producing the map-like message to colorize. | required |

Returns

| Type | Description |
| --- | --- |
| `ApplyColormap` | The configured node instance. |

#### method `process`

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

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `frame` | `dai.Buffer` | RAW ImgFrame, beta Map2D, SegmentationMask, or ImgDetections with an instance mask. Mask label 255 is background. | required |

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If an ImgFrame does not use a RAW pixel format. |
| `ValueError` | If the message type is unsupported. |

#### method `setColormap`

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

Set the color mapping applied to incoming maps.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `colormapValue` | `int | np.ndarray` | OpenCV colormap enum value or a custom OpenCV-compatible LUT. | required |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If a custom colormap is not a uint8 array of shape `(256, 1, 3)`. |

#### method `setMaxValue`

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

Set the normalization ceiling used during colorization.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `maxValue` | `int` | Maximum input value used for normalization. 0 keeps per-frame normalization. | required |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the ceiling is not a non-negative integer. |
