segment method

Future<SegmentationResult> segment(
  1. ImageInput image, {
  2. SegmentationOptions? options,
})

Assign a class to every pixel of image.

final s = await RunAnywhere.segmentation.segment(rgbImage);
print(s.classes.map((c) => c.label));

Throws SDKException when no segmentation model is loaded or the image is not packed RGB8.

Implementation

Future<SegmentationResult> segment(
  ImageInput image, {
  SegmentationOptions? options,
}) async {
  if (!DartBridge.isInitialized) {
    throw SDKException.notInitialized();
  }
  await DartBridge.ensureServicesReady();
  final modelId = await ModelGate.currentId(
    ModelCategory.MODEL_CATEGORY_SEMANTIC_SEGMENTATION,
  );
  if (modelId == null) {
    throw SDKException.componentNotReady('Segmentation');
  }
  final result = DartBridgeSegmentation.shared.segment(
    SegmentationRequest(
      image: image.toSegmentationImage(),
      options: (options ?? const SegmentationOptions()).toProto(),
    ),
  );
  return SegmentationResult.fromProto(result);
}