This feature erases a specified area of an image while preserving the background. You need to provide an original image, a mask for the area to erase, and a mask for the area to keep.
-
This document applies only to the Chinese mainland (Beijing) region. To use the model, you must use an API key from the Chinese mainland (Beijing) region.
-
The image-erase-completion model is currently available only for a free trial. After you use the free quota, you cannot call the model, and paid options are not supported. For alternatives, see Image Editing - Qwen or Image Editing - Wan 2.1.
Introduction
Image Erase and Inpaint removes elements such as people, pets, objects, text, or watermarks from an image while preserving the background. You can specify the areas to remove using an image mask. This feature does not support removal based on text prompts. The erase and inpaint technology uses advanced techniques such as AI-Generated Content (AIGC) inpainting. It applies to various scenarios, including privacy protection, content creation, and image editing.
For person removal, you can use the Person Instance Segmentation API operation. To remove one or more people, select the complete mask area for each person. This operation accurately creates a pixel-level mask for the boundary of each object.
Scenarios
-
Privacy protection: When you share photos on social media, you might need to remove certain people or sensitive information, such as specific individuals, addresses, or phone numbers. The erase and inpaint feature quickly removes these elements to prevent personal information from being leaked.
-
E-commerce product images: When you display products on e-commerce platforms, you may need to remove watermarks, logos, or other unwanted elements. The erase and inpaint feature identifies and removes these elements. This makes product images cleaner and more professional, which improves the user experience.
-
Marketing and advertising: When you create ads, you might need to combine product images with specific scenes or people. The original image may contain unwanted elements. This feature easily removes these image elements to enhance the visual creativity of posters or ads.
-
Social media content: When you share photos on social media, you may want to remove passersby or cluttered backgrounds. The AI erase and inpaint feature lets you do this easily, which improves the quality and appearance of your photos.
Features and advantages
-
The AI erase and inpaint technology intelligently fills the empty spaces left by removed elements. This makes the restored image look natural and seamless. It maintains visual harmony and a professional look without any signs of artificial editing.
-
The AI erase and inpaint feature automatically and accurately detects and removes objects of various sizes from images in multiple formats. This ensures precise removal and consistent, natural-looking inpainting.
-
The enterprise-grade platform service ensures stable image generation responses under high concurrency and high traffic, with 99.9% reliability. It offers a simple inference API operation that is easy to use, integrate, and highly compatible.
Getting started
For better results, ensure that the mask for the area to keep is clean and does not contain any objects to be erased. When you obtain the mask image from person instance segmentation, set parameters.dilate_flag=true. This expands the mask area to prevent missing the edges of the target area and creates a clear, complete mask.
-
Area to erase (mask_url): In the mask image, set the pixel values for the area to erase to a non-zero value (not pure black). Set the pixel values for all other areas to zero (pure black).
-
Area to keep (foreground_url): In the mask image, set the pixel values for the area to keep to a non-zero value (not pure black). Set the pixel values for all other areas to zero (pure black).
Image input limits:
-
Image resolution: The length of each side must be between 512 and 4,096 pixels.
-
Image format: JPEG, PNG, JPG, BMP, or WEBP.
-
Image size: Up to 10 MB.
-
URLs cannot contain Chinese characters.
|
Original image (image_url) |
Person instance segmentation mask image |
Area to erase (mask_url) |
Area to keep (foreground_url) |
Output |
|
|
|
|
|
|
The model requires a long computation time. The sample code shows how to make asynchronous calls to avoid request timeouts.
Create an API key and export the API key as an environment variable.
curl
1. Create an image erase and inpaint task
The API operation returns a task ID. You can use the task ID to query the result of the image generation.
curl --location --request POST 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--header 'X-DashScope-DataInspection: enable' \
--data-raw '{
"model": "image-erase-completion",
"input": {
"image_url": "https://huarong123.oss-cn-hangzhou.aliyuncs.com/image/%E5%9B%BE%E7%89%87%E6%93%A6%E9%99%A42-%E5%8E%9F%E5%9B%BE.png",
"mask_url": "https://huarong123.oss-cn-hangzhou.aliyuncs.com/image/%E5%9B%BE%E7%89%87%E6%93%A6%E9%99%A42-%E6%93%A6%E9%99%A4.png",
"foreground_url": "https://huarong123.oss-cn-hangzhou.aliyuncs.com/image/%E5%9B%BE%E7%89%87%E6%93%A6%E9%99%A42-%E4%BF%9D%E7%95%99.png"
},
"parameters":{
"dilate_flag":true
}
}'
2. Query the task status and result by task ID
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/13b1848b-5493-4c0e-8c44-xxxxxxxxxxxx \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
Examples
The fast_mode is suitable for scenarios that do not require a high level of detail. For more information, see Image Erase and Inpaint.
Preserve image details (default, fast_mode=false)
Sample call
|
Original image (image_url) |
Person instance segmentation mask image |
Area to erase (mask_url) |
Area to keep (foreground_url) |
Output image |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ignore image details (fast_mode=true)
Sample call
|
Original image (image_url) |
Erase area mask image (mask_url) |
Output image |
|
|
|
|
|
|
|
|
API reference
For information about the API input and response parameters, see Image Erase and Inpaint.






























