<br />

Performs image segmentation on images.

**Signature:**

```typescript
export declare class ImageSegmenter extends VisionTaskRunner 
```

## Methods

| Method | Modifiers | Description |
|---|---|---|
| [createFromOptions(wasmFileset, imageSegmenterOptions)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentercreatefromoptions) | `static` | Initializes the Wasm runtime and creates a new image segmenter from the provided options. |
| [createFromModelBuffer(wasmFileset, modelAssetBuffer)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentercreatefrommodelbuffer) | `static` | Initializes the Wasm runtime and creates a new image segmenter based on the provided model asset buffer. |
| [createFromModelPath(wasmFileset, modelAssetPath)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentercreatefrommodelpath) | `static` | Initializes the Wasm runtime and creates a new image segmenter based on the path to the model asset. |
| [setOptions(options)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersetoptions) |   | Sets new options for the image segmenter. Calling `setOptions()` with a subset of options only affects those options. You can reset an option back to its default value by explicitly setting it to `undefined`. |
| [segment(image, callback)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegment) |   | Performs image segmentation on the provided single image and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `image`. |
| [segment(image, imageProcessingOptions, callback)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegment_1) |   | Performs image segmentation on the provided single image and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `image`. |
| [segment(image)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegment_2) |   | Performs image segmentation on the provided single image and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-throughput applications. Only use this method when the ImageSegmenter is created with running mode `image`. |
| [segment(image, imageProcessingOptions)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegment_3) |   | Performs image segmentation on the provided single image and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-v applications. Only use this method when the ImageSegmenter is created with running mode `image`. |
| [segmentForVideo(videoFrame, timestamp, callback)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegmentforvideo) |   | Performs image segmentation on the provided video frame and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `video`. |
| [segmentForVideo(videoFrame, timestamp, imageProcessingOptions, callback)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegmentforvideo_1) |   | Performs image segmentation on the provided video frame and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `video`. |
| [segmentForVideo(videoFrame, timestamp)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegmentforvideo_2) |   | Performs image segmentation on the provided video frame and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-throughput applications. Only use this method when the ImageSegmenter is created with running mode `video`. |
| [segmentForVideo(videoFrame, timestamp, imageProcessingOptions)](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentersegmentforvideo_3) |   | Performs image segmentation on the provided video frame and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-v applications. Only use this method when the ImageSegmenter is created with running mode `video`. |
| [getLabels()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.imagesegmenter.md.txt#imagesegmentergetlabels) |   | Get the category label list of the ImageSegmenter can recognize. For `CATEGORY_MASK` type, the index in the category mask corresponds to the category in the label list. For `CONFIDENCE_MASK` type, the output mask list at index corresponds to the category in the label list. If there is no labelmap provided in the model file, empty label array is returned. |

## ImageSegmenter.createFromOptions() {#imagesegmentercreatefromoptions}

Initializes the Wasm runtime and creates a new image segmenter from the provided options.

**Signature:**

```typescript
static createFromOptions(wasmFileset: WasmFileset, imageSegmenterOptions: ImageSegmenterOptions): Promise<ImageSegmenter>;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| imageSegmenterOptions | ImageSegmenterOptions | The options for the Image Segmenter. Note that either a path to the model asset or a model buffer needs to be provided (via `baseOptions`). |

**Returns:**

Promise\<ImageSegmenter\>

## ImageSegmenter.createFromModelBuffer() {#imagesegmentercreatefrommodelbuffer}

Initializes the Wasm runtime and creates a new image segmenter based on the provided model asset buffer.

**Signature:**

```typescript
static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<ImageSegmenter>;
```

### 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\<ImageSegmenter\>

## ImageSegmenter.createFromModelPath() {#imagesegmentercreatefrommodelpath}

Initializes the Wasm runtime and creates a new image segmenter based on the path to the model asset.

**Signature:**

```typescript
static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<ImageSegmenter>;
```

### 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\<ImageSegmenter\>

## ImageSegmenter.setOptions() {#imagesegmentersetoptions}

Sets new options for the image segmenter. Calling `setOptions()` with a subset of options only affects those options. You can reset an option back to its default value by explicitly setting it to `undefined`.

**Signature:**

```typescript
setOptions(options: ImageSegmenterOptions): Promise<void>;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| options | ImageSegmenterOptions | The options for the image segmenter. |

**Returns:**

Promise\<void\>

## ImageSegmenter.segment() {#imagesegmentersegment}

Performs image segmentation on the provided single image and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `image`.

**Signature:**

```typescript
segment(image: ImageSource, callback: ImageSegmenterCallback): void;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| image | ImageSource | An image to process. |
| callback | ImageSegmenterCallback | The callback that is invoked with the segmented masks. The lifetime of the returned data is only guaranteed for the duration of the callback. |

**Returns:**

void

## ImageSegmenter.segment() {#imagesegmentersegment_1}

Performs image segmentation on the provided single image and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `image`.

**Signature:**

```typescript
segment(image: ImageSource, imageProcessingOptions: ImageProcessingOptions, callback: ImageSegmenterCallback): void;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| image | ImageSource | An image to process. |
| imageProcessingOptions | ImageProcessingOptions | the `ImageProcessingOptions` specifying how to process the input image before running inference. |
| callback | ImageSegmenterCallback | The callback that is invoked with the segmented masks. The lifetime of the returned data is only guaranteed for the duration of the callback. |

**Returns:**

void

## ImageSegmenter.segment() {#imagesegmentersegment_2}

Performs image segmentation on the provided single image and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-throughput applications. Only use this method when the ImageSegmenter is created with running mode `image`.

**Signature:**

```typescript
segment(image: ImageSource): ImageSegmenterResult;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| image | ImageSource | An image to process. |

**Returns:**

ImageSegmenterResult

## ImageSegmenter.segment() {#imagesegmentersegment_3}

Performs image segmentation on the provided single image and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-v applications. Only use this method when the ImageSegmenter is created with running mode `image`.

**Signature:**

```typescript
segment(image: ImageSource, imageProcessingOptions: ImageProcessingOptions): ImageSegmenterResult;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| image | ImageSource | An image to process. |
| imageProcessingOptions | ImageProcessingOptions | the `ImageProcessingOptions` specifying how to process the input image before running inference. |

**Returns:**

ImageSegmenterResult

## ImageSegmenter.segmentForVideo() {#imagesegmentersegmentforvideo}

Performs image segmentation on the provided video frame and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `video`.

**Signature:**

```typescript
segmentForVideo(videoFrame: ImageSource, timestamp: number, callback: ImageSegmenterCallback): void;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| videoFrame | ImageSource | A video frame to process. |
| timestamp | number | The timestamp of the current frame, in ms. |
| callback | ImageSegmenterCallback | The callback that is invoked with the segmented masks. The lifetime of the returned data is only guaranteed for the duration of the callback. |

**Returns:**

void

## ImageSegmenter.segmentForVideo() {#imagesegmentersegmentforvideo_1}

Performs image segmentation on the provided video frame and invokes the callback with the response. The method returns synchronously once the callback returns. Only use this method when the ImageSegmenter is created with running mode `video`.

**Signature:**

```typescript
segmentForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions: ImageProcessingOptions, callback: ImageSegmenterCallback): void;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| videoFrame | ImageSource | A video frame to process. |
| timestamp | number | The timestamp of the current frame, in ms. |
| imageProcessingOptions | ImageProcessingOptions | the `ImageProcessingOptions` specifying how to process the input frame before running inference. |
| callback | ImageSegmenterCallback | The callback that is invoked with the segmented masks. The lifetime of the returned data is only guaranteed for the duration of the callback. |

**Returns:**

void

## ImageSegmenter.segmentForVideo() {#imagesegmentersegmentforvideo_2}

Performs image segmentation on the provided video frame and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-throughput applications. Only use this method when the ImageSegmenter is created with running mode `video`.

**Signature:**

```typescript
segmentForVideo(videoFrame: ImageSource, timestamp: number): ImageSegmenterResult;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| videoFrame | ImageSource | A video frame to process. |
| timestamp | number |   |

**Returns:**

ImageSegmenterResult

## ImageSegmenter.segmentForVideo() {#imagesegmentersegmentforvideo_3}

Performs image segmentation on the provided video frame and returns the segmentation result. This method creates a copy of the resulting masks and should not be used in high-v applications. Only use this method when the ImageSegmenter is created with running mode `video`.

**Signature:**

```typescript
segmentForVideo(videoFrame: ImageSource, timestamp: number, imageProcessingOptions: ImageProcessingOptions): ImageSegmenterResult;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| videoFrame | ImageSource | A video frame to process. |
| timestamp | number | The timestamp of the current frame, in ms. |
| imageProcessingOptions | ImageProcessingOptions | the `ImageProcessingOptions` specifying how to process the input frame before running inference. |

**Returns:**

ImageSegmenterResult

## ImageSegmenter.getLabels() {#imagesegmentergetlabels}

Get the category label list of the ImageSegmenter can recognize. For `CATEGORY_MASK` type, the index in the category mask corresponds to the category in the label list. For `CONFIDENCE_MASK` type, the output mask list at index corresponds to the category in the label list. If there is no labelmap provided in the model file, empty label array is returned.

**Signature:**

```typescript
getLabels(): string[];
```

**Returns:**

string\[\]