Skip to main content
Version: Next

Type Alias: SemanticSegmenter<L>

SemanticSegmenter<L> = object

Defined in: extensions/cv/tasks/semanticSegmentation.ts:80

Semantic segmentation task runner.

Type Parameters​

L​

L extends PropertyKey = string

The type representing the segmentation labels.

Properties​

dispose()​

readonly dispose: () => void

Defined in: extensions/cv/tasks/semanticSegmentation.ts:84

Releases all allocated native resources.

Returns​

void


segment()​

readonly segment: (input, colormap?) => Promise<SemanticSegmentationResult<L>>

Defined in: extensions/cv/tasks/semanticSegmentation.ts:109

Runs semantic segmentation asynchronously.

For models returning logits for all classes, this performs an argmax over the class dimensions to identify the highest-probability class per pixel, then maps each class index to an RGBA color from the colormap. The final mapped colormap is returned in the result.

For single-channel models, this applies sigmoid to logits or uses the model's probabilities directly when binaryOutput is 'probabilities'. It scales the probabilities to grayscale (0-255) and returns an RGBA mask with an undefined colormap.

Parameters​

input​

ImageBuffer

The input image buffer to segment.

colormap?​

Partial<ColorMap<L>>

Optional partial color mapping overrides for labels (applicable only for multi-class models). If not provided, a default colormap is automatically generated with distinct, high-contrast colors (with the first label defaulting to transparent). If a partial map is provided, any labels omitted from it will default to being rendered as fully transparent.

Returns​

Promise<SemanticSegmentationResult<L>>

A promise resolving to the segmentation result.

Throws​

With code RESOURCE_BUSY if the model is in use, or RESOURCE_DISPOSED if disposed.


segmentWorklet()​

readonly segmentWorklet: (input, colormap?) => SemanticSegmentationResult<L>

Defined in: extensions/cv/tasks/semanticSegmentation.ts:118

Synchronous version of segment to be executed directly on the caller or worklet thread.

Parameters​

input​

ImageBuffer

colormap?​

Partial<ColorMap<L>>

Returns​

SemanticSegmentationResult<L>