# \[Alpha] Text-Guided Segmentation

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

This means that the feature (or parts of it) might be deprecated with two week warning.
{% 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="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2F9R6RB0S2oTxgnCgR3GIU%2Fsamsung-memory-NTisn7FckN4-unsplash.jpg?alt=media&#x26;token=8709cd83-9f70-47a0-8517-ecc73d46b7ea" alt=""></td><td align="center"><em>(original image)</em></td></tr><tr><td><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2FegpfrdoucfQM5FSHolU6%2Fsamsung-memory-NTisn7FckN4-unsplash-Photoroom.png?alt=media&#x26;token=12059584-3a88-43cb-b630-a6995d4e1eb4" alt=""></td><td align="center"><em>(default segmentation)</em></td></tr><tr><td><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2FvB4EJy2WrKkZCsZPmuiQ%2Flaptop.png?alt=media&#x26;token=89c483c0-3676-4e8d-b97d-58ce9f3fcf6d" alt=""></td><td align="center"><code>segmentation.prompt=laptop</code></td></tr><tr><td><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2F9Kc72sGSDjOIpD9UIbUY%2Fmemory-card.png?alt=media&#x26;token=5ebc2ae3-32ea-43c0-87ec-28dbd605d150" alt=""></td><td align="center"><code>segmentation.prompt=memory card</code></td></tr><tr><td></td><td align="center"><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2Fr50VlgCoGVfuiOa8YOV4%2Flaptop-hand-arm.png?alt=media&#x26;token=b1349228-abea-463a-aa25-6b2f095a8395" 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="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2Fwq3kEP38VdxyHIrtcmhR%2Fcristofer-maximilian-AqLIkOzWDAk-unsplash.jpg?alt=media&#x26;token=f9864f15-3ad9-41d6-8d8e-5f98282f75e4" alt=""></td><td align="center"><em>(original image)</em></td></tr><tr><td><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2FRBoZSuqP0jXqy8ah9SRF%2Fclothe.png?alt=media&#x26;token=ceb8ea31-180b-4fb5-b359-724331ff0e32" alt=""></td><td align="center"><em>(default segmentation)</em></td></tr><tr><td><img src="https://2855892273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1SYxn7dWbQYsNtUdJE3f%2Fuploads%2FexO7Hmv7dQBlFSyIcyLi%2Fclothe-no-hanger.png?alt=media&#x26;token=29b6b07d-4cf8-420e-b540-2997449a3e3b" 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>
