Skip to main content
Image editing

Image erase completion

Remove people, objects, text, or watermarks from an image and fill in the erased area

image-erase-completion removes one or more elements from an image, such as people, pets, objects, text, or watermarks, and fills in the erased area while preserving the background. You mark the area to erase with a mask image. Quick links: API reference: Create a task, Query the result Supported regions: China North 2 (Beijing) only. Use an API key created in that region and the https://cn-beijing.maas.qwencloudapi.com endpoint. See Regions and endpoints.
The model is available for free trial only. After the free quota is used, calls are no longer possible. As an alternative, use Image editing.

Image requirements

ImageRequirements
Input imageJPEG, PNG, JPG, BMP, or WEBP; width and height between 512 and 4,096 pixels; up to 10 MB
Mask imageJPG, JPEG, PNG, HEIF, or WEBP; same resolution limits as the input image. Non-zero pixels mark the area to erase.
Foreground image (optional)JPG, JPEG, PNG, HEIF, or WEBP; same resolution limits as the input image. Non-zero pixels mark the area to preserve.
The URL must be publicly accessible over HTTP or HTTPS and must not contain Chinese characters. Base64-encoded images are also accepted.

How it works

  1. Create a task: Send the input image, the mask image, and optional parameters. The API returns a task_id.
  2. Query the result: Poll GET /tasks/{task_id} until task_status is SUCCEEDED, then download the result image from output.results[].url.
To create a mask, paint the area to erase on a canvas the same size as the input image. To remove a person, you can use Person instance segmentation to generate the mask automatically.

Request example

import os
import time
import requests

# China North 2 (Beijing). This model is available only in this region.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
BASE_URL = "https://cn-beijing.maas.qwencloudapi.com/api/v1"
headers = {
  "Authorization": f"Bearer {os.getenv('DASHSCOPE_API_KEY')}",
  "Content-Type": "application/json",
  "X-DashScope-Async": "enable",
}

response = requests.post(
  f"{BASE_URL}/services/aigc/image2image/image-synthesis",
  headers=headers,
  json={
    "model": "image-erase-completion",
    "input": {
      "image_url": "https://example.com/input.png",
      "mask_url": "https://example.com/mask.png"
    },
    "parameters": {"dilate_flag": True}
  },
)
task_id = response.json()["output"]["task_id"]

while True:
  result = requests.get(f"{BASE_URL}/tasks/{task_id}", headers=headers).json()
  status = result["output"]["task_status"]
  if status in ("SUCCEEDED", "FAILED"):
    break
  time.sleep(5)

print(result)

Parameters

ParameterTypeRequiredDescription
image_urlstringYesInput image URL or Base64-encoded image.
mask_urlstringYesMask image URL or Base64-encoded image. Non-zero pixels mark the area to erase.
foreground_urlstringNoForeground image URL or Base64-encoded image. Non-zero pixels mark the area to preserve.
fast_modebooleanNoEnables fast mode. Inference takes about one quarter of the standard time, with less detail. Default: false.
dilate_flagbooleanNoExpands the mask before erasing. Set to true when the mask is generated by an algorithm and to false when you paint it manually. Default: true.
add_watermarkbooleanNoAdds a "Generated by AI" watermark to the bottom-left corner of the output image. Default: true.

FAQ

How do I erase a person? Run Person instance segmentation on the image, use its mask image as mask_url, and set dilate_flag to true. How long is the result URL valid? 24 hours after the task succeeds. Download the image promptly. How is the model billed? Billing is based on successfully generated images. A failed task is not billed. The model is currently free trial only.