Parameters
ImageInput
required
RGB image as file path, URL, PIL Image, or numpy array.
Optional[str]
Text prompt describing objects to segment (exclusive with points/boxes).
Optional[Iterable[Iterable[float]]]
List of [x, y] point coordinates (exclusive with text/boxes).
Optional[Iterable[Iterable[float]]]
List of [x0, y0, x1, y1] box coordinates (exclusive with text/points).
Optional[Iterable[int]]
Required for points/boxes. 1=foreground, 0=background.
Optional[float]
Optional HTTP timeout in seconds.
Returns
np.ndarray: Binary segmentation mask as numpy array (H, W) with dtype uint8. Foreground pixels are 255, background pixels are 0.Example
run()— Returns a single union mask. Use when you only need the combined segmentation.run_with_detections()— Returns the union mask plus per-instance masks, bounding boxes, and confidence scores. Use when you need individual object information (e.g. counting objects, filtering by confidence, or processing instances separately). Only available for text and box prompts — point prompts have no detection semantics.
run_with_detections()
Same call signature as run(). Returns a dict with keys:
union_mask— Combined binary mask(H, W), dtypeuint8(same asrun()output)masks— List of per-instance binary masks, each(H, W)dtypeuint8boxes— List of[x0, y0, x1, y1]bounding boxes (text/box prompts only)scores— List of confidence scores (sorted descending)
masks, boxes, and scores will be empty lists.
Example Output — run()

run() when you only need the combined mask — e.g. masking a region, computing area, or passing to a downstream model.
Example Output — run_with_detections()

run_with_detections() when you need per-instance information — e.g. counting objects, filtering by confidence, or processing each instance separately. Works with text and box prompts only.