Edit in GitHubLog an issue

Enhance image mask quality with Refine Mask

Learn how to use the Refine Masks API in your code workflows with this guide to enhance image mask quality.

Overview

In this tutorial, you'll learn how to use the Mask Refinement API to enhance the quality of your image masks. Whether you're working on image segmentation, graphic design, or any project that requires precise mask details, our API will help you achieve cleaner, smoother edges and more accurate mask representations.

Follow along to see how easy it is to integrate this powerful tool into your workflow and elevate your image-processing tasks.

About the Refine Masks API

Before getting into the code, let's consider how the Refine Masks API works at a high level.

  • You begin with a source image, uploaded to one of the supported cloud storage providers. See the API reference for the list of supported cloud storage providers.
  • You then provide a masked version of the image. The Photoshop API will refine the mask according to the source image.
  • You can provide a single mask for the input image that needs to be refined.

Prerequisites

  • Valid credentials. If you don't have them yet, first visit the Firefly Services Getting Started guide to obtain a client_id and client_secret.
  • Node.js installed on your machine and basic familiarity with JavaScript.
  • Store the source and mask images below in a supported cloud storage provider.

Source image

Source image

Mask image

Mask image

Using color decontamination

The colorDecontamination parameter determines whether color decontamination should be applied to the foreground of the input image. When set to true, the API will remove any color fringing and contamination from the foreground, ensuring a more accurate and clean RGBA mask output.

Calling the Refine Masks API

Here is a simple example of the request body required to use the Refine Masks API:

Copied to your clipboard
{
"image": {
"source": {
"url": "<source_image_url>"
}
},
"mask": {
"source": {
"url": "<mask_image_url>"
}
},
"colorDecontamination": false
}

The source of the images, take pre-signed URLs from the cloud storage provider.

Generated result

You can see in the image below that the mask has been refined.

Result without color decontamination

Generated Result

Result with color decontamination

Color Decontaminated Result

Complete sample code

If it's helpful to see a complete implementation, we've provide the full JavaScript code sample.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2025 Adobe. All rights reserved.