# \[Preview] Text-Guided Segmentation

{% hint style="warning" %}
Warning: Text-Guided Segmentation is available as a preview feature.

As such, please be aware that there could be breaking changes with a 2-week notice period.
{% endhint %}

Text-Guided Segmentation allows you to have more control over which parts of the input image should be kept by the segmentation mode and which parts should be removed.

Text-Guided segmentation is controlled through 3 parameters:

* `segmentation.prompt`: A textual description of what the segmentation should keep. (required, comma separated values are allowed, use singular rather than plural)
* `segmentation.negativePrompt`: A textual description of what the segmentation should remove. (optional, comma separated values are allowed, use singular rather than plural)
* `segmentation.mode`: When set to `keepSalientObject`, the salient object of the image (i.e. what the default segmentation would have kept) will also be kept by the segmentation. (optional)

{% hint style="info" %}
For the arguments `segmentation.prompt` and `segmentation.negativePrompt`, please use the singular rather than the plural. (e.g. `laptop` rather than `laptops`)

If you want the segmentation to keep a person, we recommend setting `segmentation.mode=keepSalientObject` rather than `segmentation.prompt=person`. (the reason why is that the `prompt` is currently is less performant when dealing with fine details, like hair)
{% endhint %}

To help better understand how the feature works, here are some examples:

<table data-card-size="large" data-view="cards" data-full-width="false"><thead><tr><th></th><th align="center"></th></tr></thead><tbody><tr><td><img src="/files/0OQiIPBWtv4jFwntLo7x" alt=""></td><td align="center"><em>(original image)</em></td></tr><tr><td><img src="/files/ro8BBCTyCU4qGW07fyL5" alt=""></td><td align="center"><em>(default segmentation)</em></td></tr><tr><td><img src="/files/l2IZxzZB50r3TxFzFOJW" alt=""></td><td align="center"><code>segmentation.prompt=laptop</code></td></tr><tr><td><img src="/files/ZC3cvgZyjYairlx2grS1" alt=""></td><td align="center"><code>segmentation.prompt=memory card</code></td></tr><tr><td></td><td align="center"><img src="/files/1niNqfo3NNJlAnBuISuC" alt=""><br><code>segmentation.prompt=laptop, hand, arm</code></td></tr><tr><td></td><td align="center"></td></tr></tbody></table>

<table data-card-size="large" data-view="cards" data-full-width="false"><thead><tr><th></th><th align="center"></th></tr></thead><tbody><tr><td><img src="/files/sfndLGeIsQp3Govs2kl1" alt=""></td><td align="center"><em>(original image)</em></td></tr><tr><td><img src="/files/U8SIqLup4DRjhEKw38rJ" alt=""></td><td align="center"><em>(default segmentation)</em></td></tr><tr><td><img src="/files/Bl9YlpCzouPLcCDuYAn0" alt=""></td><td align="center"><code>segmentation.prompt=tee-shirt</code><br>and<br><code>segmentation.negativePrompt=hanger</code></td></tr><tr><td></td><td align="center"></td></tr></tbody></table>

If you want to give it a try, here are some code snippets to reproduce the examples above:

```bash
curl --request POST \
  --url https://image-api.photoroom.com/v2/edit \
  --header 'x-api-key: YOUR_API_KEY' \
  --form 'imageFile=@"/path/to/image.jpeg"' \
  --form 'referenceBox="originalImage"' \
  --form 'segmentation.prompt="laptop, hand, arm"' \
  --output result-laptop-hand-arm.png
```

<a href="https://try-api.photoroom.com/?referenceBox=originalImage&#x26;segmentation.prompt=laptop%2C%20hand%2C%20arm" class="button primary">Try it now!</a>

```bash
curl --request POST \
  --url https://image-api.photoroom.com/v2/edit \
  --header 'x-api-key: YOUR_API_KEY' \
  --form 'imageFile=@"/path/to/image.jpeg"' \
  --form 'referenceBox="originalImage"' \
  --form 'segmentation.prompt="tee-shirt"' \
  --form 'segmentation.negativePrompt="hanger"' \
  --output result-tee-shirt-no-hanger.png
```

<a href="https://try-api.photoroom.com/?referenceBox=originalImage&#x26;segmentation.prompt=tee-shirt&#x26;segmentation.negativePrompt=hanger" class="button primary">Try it now!</a>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.photoroom.com/image-editing-api-plus-plan/preview-text-guided-segmentation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
