Skip to main content
Segment image with SAM-2 given point/box prompts.

Parameters

Union[str, Image.Image, np.ndarray]
required
RGB image.
List[List[int]]
required
List of [x, y] pixel coordinates.
List[int]
required
1 = foreground, 0 = background per prompt.
bool
default:"False"
If True returns multiple masks.
str
default:"'image'"
Endpoint mode; only “image” currently supported.
float | None
HTTP timeout.

Returns

np.ndarray: Binary segmentation mask as numpy array (H, W) with dtype uint8. Foreground pixels are 255, background pixels are 0.

Example

Example Output

SAM2 point-prompted segmentation output

Related topics

sam2