Skip to main content
Version: 0.11.x

Function: applyColormap()

applyColormap(src, dst, colormap): Tensor

Defined in: extensions/cv/ops/image.ts:260

Applies a colormap to a single-channel image tensor, mapping class indices to RGBA colors.

This operation iterates over each index/class ID in the source tensor, looks up its corresponding RGBA color in the provided colormap palette, and writes it to the destination tensor.

Parameters​

src​

Tensor

The source index/mask image tensor. Expected shape [H, W, 1] in HWC layout with data type int32 containing class indices.

dst​

Tensor

The pre-allocated destination image tensor to write the mapped RGBA values to. Expected shape [H, W, 4] in HWC layout with data type uint8.

colormap​

[number, number, number, number][]

An array of RGBA color arrays [R, G, B, A] corresponding to each class index. The size of this list must cover all class indices present in src.

Returns​

Tensor

The destination image tensor with the applied colormap of shape [H, W, 4] and data type uint8.

Throws​

With code INVALID_ARGUMENT if tensor shapes, layouts, or data types are invalid, RESOURCE_BUSY if a tensor is in use, or RESOURCE_DISPOSED if either tensor was disposed.