MediaPipeTasksVision Framework Reference

InteractiveSegmenter

class InteractiveSegmenter: NSObject

Class that performs interactive segmentation on images using split mode.

This API optimizes performance by splitting the model into an encoder (feature extraction that runs once per image) and a decoder (lightweight heatmap generation that runs per user stroke).

  • Creates a new instance of InteractiveSegmenter from the given InteractiveSegmenterOptions.

    Declaration

    Swift

    init(options: InteractiveSegmenterOptions) throws

    Parameters

    options

    The options of type InteractiveSegmenterOptions to use for configuring the InteractiveSegmenter.

    Return Value

    A new instance of InteractiveSegmenter with the given options. nil if there is an error in initializing the interactive segmenter.

  • Performs segmentation on the previously set image using the provided user's strokes. This runs the decoder part of the split model.

    Declaration

    Swift

    func segment(strokes: [Stroke]) throws -> MPImage

    Parameters

    strokes

    An array of MPPStroke objects representing the user interaction.

    Return Value

    An MPImage that contains the segmented mask.

  • Sets the image to be segmented. This runs the encoder part of the split model. This method must be called before calling segmentWithStrokes:error:.

    Declaration

    Swift

    func set(image: MPImage) throws

    Parameters

    image

    The MPImage on which segmentation is to be performed.

    Return Value

    YES if the image was successfully set and encoded, NO otherwise.