Performs interactive segmentation on images using split mode architecture. Interactive Segmenter splits segmentation into two distinct steps: 1. Set an image with setImage() (executes heavy feature extraction once). 2. Segment with segment() one or more times efficiently providing strokes, allowing the user to fine tune the produced segmentation mask.
Signature:
export declare class InteractiveSegmenter extends TaskRunner
Methods
| Method | Modifiers | Description |
|---|---|---|
| createFromOptions(wasmFileset, options) | static |
Initializes the Wasm runtime and creates a new interactive segmenter from the provided options. |
| createFromModelBuffer(wasmFileset, modelAssetBuffer) | static |
Initializes the Wasm runtime and creates a new interactive segmenter based on the provided model asset buffer. |
| createFromModelPath(wasmFileset, modelAssetPath) | static |
Initializes the Wasm runtime and creates a new interactive segmenter based on the path to the model asset. |
| setOptions(options) | Sets new options for the interactive segmenter. Calling setOptions() with a subset of options only affects those options. |
|
| setImage(image) | Sets the input image for segmentation, executing the encoder model once. Extracts raw pixel bytes across diverse sources (Canvas, ImageData, TexImageSource, DOM elements) and copies them across Wasm heap memory into the native C++ engine. | |
| segment(strokes) | Performs segmentation using the provided strokes, executing the lightweight decoder model. Serializes user strokes to protocol buffers, invokes native inference, and creates a deep copy of the resulting Wasm heap mask data to safeguard against native buffer deallocation. | |
| close() | Closes and cleans up the resources held by this task. |
InteractiveSegmenter.createFromOptions()
Initializes the Wasm runtime and creates a new interactive segmenter from the provided options.
Signature:
static createFromOptions(wasmFileset: WasmFileset, options: InteractiveSegmenterOptions): Promise<InteractiveSegmenter>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| options | InteractiveSegmenterOptions | The options for the Interactive Segmenter. Note that either a path to the model asset or a model buffer needs to be provided (via baseOptions). |
Returns:
Promise<InteractiveSegmenter>
InteractiveSegmenter.createFromModelBuffer()
Initializes the Wasm runtime and creates a new interactive segmenter based on the provided model asset buffer.
Signature:
static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<InteractiveSegmenter>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| modelAssetBuffer | Uint8Array | ReadableStreamDefaultReader | An array or a stream containing a binary representation of the model. |
Returns:
Promise<InteractiveSegmenter>
InteractiveSegmenter.createFromModelPath()
Initializes the Wasm runtime and creates a new interactive segmenter based on the path to the model asset.
Signature:
static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<InteractiveSegmenter>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| modelAssetPath | string | The path to the model asset. |
Returns:
Promise<InteractiveSegmenter>
InteractiveSegmenter.setOptions()
Sets new options for the interactive segmenter. Calling setOptions() with a subset of options only affects those options.
Signature:
setOptions(options: InteractiveSegmenterOptions): Promise<void>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| options | InteractiveSegmenterOptions | The options for the interactive segmenter. |
Returns:
Promise<void>
InteractiveSegmenter.setImage()
Sets the input image for segmentation, executing the encoder model once. Extracts raw pixel bytes across diverse sources (Canvas, ImageData, TexImageSource, DOM elements) and copies them across Wasm heap memory into the native C++ engine.
Signature:
setImage(image: TexImageSource): void;
Parameters
| Parameter | Type | Description |
|---|---|---|
| image | TexImageSource | An image to process. |
Returns:
void
InteractiveSegmenter.segment()
Performs segmentation using the provided strokes, executing the lightweight decoder model. Serializes user strokes to protocol buffers, invokes native inference, and creates a deep copy of the resulting Wasm heap mask data to safeguard against native buffer deallocation.
Signature:
segment(strokes: readonly Stroke[]): MPMask;
Parameters
| Parameter | Type | Description |
|---|---|---|
| strokes | readonly Stroke[] | The sequence of user strokes. |
Returns:
MPMask
InteractiveSegmenter.close()
Closes and cleans up the resources held by this task.
Signature:
close(): void;
Returns:
void