getSegmentationMask method
Future<SegmentationMask>
getSegmentationMask(
- Uint8List imageBytes, {
- IsolateOutputFormat outputFormat = IsolateOutputFormat.float32,
- double binaryThreshold = 0.5,
Segments an image to separate foreground (people) from background.
Returns a SegmentationMask with per-pixel probabilities indicating foreground vs background.
Parameters:
outputFormat: Controls the output format for transfer efficiency- IsolateOutputFormat.float32: Full precision mask (largest transfer)
- IsolateOutputFormat.uint8: 8-bit grayscale (4x smaller)
- IsolateOutputFormat.binary: Binary mask at threshold (smallest)
binaryThreshold: Threshold for binary output (default 0.5)
Throws StateError if initializeSegmentation hasn't been called. Throws SegmentationException on inference failure.
Implementation
Future<SegmentationMask> getSegmentationMask(
Uint8List imageBytes, {
IsolateOutputFormat outputFormat = IsolateOutputFormat.float32,
double binaryThreshold = 0.5,
}) async {
_requireReady();
_requireSegmentationReady();
final Map<String, dynamic> result =
await _sendSegmentationRequest<Map<String, dynamic>>('segment', {
'bytes': TransferableTypedData.fromList([imageBytes]),
'outputFormat': outputFormat.index,
'binaryThreshold': binaryThreshold,
});
return _deserializeMask(result);
}