> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GSAM2

> Text-prompted image segmentation (Grounded SAM 2)

Segment objects in an image using a text prompt. Combines Grounding DINO with SAM 2.

## Parameters

<ParamField body="image_input" type="str | PIL.Image | np.ndarray" required>
  RGB image as file path, URL, PIL Image, or numpy array.
</ParamField>

<ParamField body="prompt" type="str" required>
  Text description of objects to segment.
</ParamField>

<ParamField body="box_threshold" type="float">
  Confidence threshold (0.0–1.0) for filtering detections.
</ParamField>

<ParamField body="text_threshold" type="float">
  Text confidence threshold (0.0–1.0).
</ParamField>

<ParamField body="nms_threshold" type="float">
  Non-Maximum Suppression threshold (0.0–1.0).
</ParamField>

<ParamField body="timeout" type="float | None">
  Optional HTTP timeout.
</ParamField>

## Returns

`np.ndarray` — Binary segmentation mask of shape `(H, W)` with dtype `uint8`. Foreground pixels are `255`, background is `0`.

## Example Output

<img src="https://mintcdn.com/scaledfoundations/lgZgGQWKvUIw0C7n/assets/images/cortex/gsam2-output.jpg?fit=max&auto=format&n=lgZgGQWKvUIw0C7n&q=85&s=99dcf4265e0428fcfedc420540a52dd8" alt="GSAM2 text-prompted segmentation output" width="1056" height="552" data-path="assets/images/cortex/gsam2-output.jpg" />

## Example

```python theme={null}
from grid_cortex_client import CortexClient
import numpy as np
from PIL import Image

client = CortexClient()
img = Image.open("scene.jpg")  # 640x480 RGB
mask = client.run(model_id="gsam2", image_input=img, prompt="street")

print(mask.shape, mask.dtype)
# (480, 640) uint8

foreground = np.count_nonzero(mask)
print(f"foreground pixels: {foreground} ({foreground / mask.size * 100:.1f}%)")
# foreground pixels: 138737 (45.2%)
```


## Related topics

- [Grounded SAM 2](/models/segmentation/gsam2.md)
- [AI Models](/simulation/airgen/examples/ai-models.md)
- [SAM2](/models/cortex/sam2.md)
- [Segment Anything 2](/models/segmentation/sam2.md)
- [GRID Cortex Client](/models/cortex.md)
