# EVF-SAM2 Segmentation

> EVF-SAM2 combines natural language understanding with advanced segmentation capabilities, allowing you to precisely mask image regions using intuitive positive and negative text prompts.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/evf-sam`
- **Model ID**: `fal-ai/evf-sam`
- **Category**: image-to-image
- **Kind**: inference
**Tags**: segmentation, mask



## Pricing

- **Price**: $0.005 per 1

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`prompt`** (`string`, _required_):
  The prompt to generate segmentation from.
  - Examples: "Cat in the middle of the image"

- **`negative_prompt`** (`string`, _optional_):
  Areas to exclude from segmentation (will be subtracted from prompt results)

- **`semantic_type`** (`boolean`, _optional_):
  Enable semantic level segmentation for body parts, background or multi objects
  - Default: `false`

- **`image_url`** (`string`, _required_):
  URL of the input image
  - Examples: "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png"

- **`mask_only`** (`boolean`, _optional_):
  Output only the binary mask instead of masked image Default value: `true`
  - Default: `true`

- **`use_grounding_dino`** (`boolean`, _optional_):
  Use GroundingDINO instead of SAM for segmentation
  - Default: `false`

- **`revert_mask`** (`boolean`, _optional_):
  Invert the mask (background becomes foreground and vice versa)
  - Default: `false`

- **`blur_mask`** (`integer`, _optional_):
  Apply Gaussian blur to the mask. Value determines kernel size (must be odd number)
  - Default: `0`
  - Range: `0` to `50`

- **`expand_mask`** (`integer`, _optional_):
  Expand/dilate the mask by specified pixels
  - Default: `0`
  - Range: `0` to `20`

- **`fill_holes`** (`boolean`, _optional_):
  Fill holes in the mask using morphological operations
  - Default: `false`



**Required Parameters Example**:

```json
{
  "prompt": "Cat in the middle of the image",
  "image_url": "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png"
}
```

**Full Example**:

```json
{
  "prompt": "Cat in the middle of the image",
  "image_url": "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png",
  "mask_only": true
}
```


### Output Schema

The API returns the following output format:

- **`image`** (`File`, _required_):
  The segmented output image



**Example Response**:

```json
{
  "image": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019
  }
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/evf-sam \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "prompt": "Cat in the middle of the image",
     "image_url": "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png"
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/evf-sam",
    arguments={
        "prompt": "Cat in the middle of the image",
        "image_url": "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png"
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/evf-sam", {
  input: {
    prompt: "Cat in the middle of the image",
    image_url: "https://storage.googleapis.com/falserverless/web-examples/evf-sam2/evfsam2-cat.png"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/evf-sam)
- [API Documentation](https://fal.ai/models/fal-ai/evf-sam/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/evf-sam)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
