[Alpha] Text-Guided Segmentation

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.

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.keepSalientObject: When set to true, the salient object of the image (i.e. what the default segmentation would have kept) will also be kept by the segmentation. (optional)

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.keepSalientObject=true rather than segmentation.prompt=person. (the reason why is that the prompt is currently is less performant when dealing with fine details, like hair)

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

(original image)

(default segmentation)

segmentation.prompt=laptop

segmentation.prompt=memory card

(original image)

(default segmentation)

segmentation.prompt=tee-shirt and segmentation.negativePrompt=hanger

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

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
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

Last updated