Image Matting

Automatically separate the subject from the background and output a cutout with a transparent alpha channel and hair-level soft edges, ready for compositing, covers, and posters.

Prefer not to code? Upload files and process them in Gitruck Toolbox. Just sign in; results match this API.Open Image Background Remover →

Examples

OriginalForeground (transparent)Background plate (subject transparent)
OriginalForegroundBackground plate

The foreground layer and background plate are complementary — stacking them reconstructs the original. The foreground is ready for compositing; the background plate (returned when output_background=true) can be reused as a new background.

Create Task

Basic Information

ItemValue
Request MethodPOST
Request Path/task/image_matting
Content-Typeapplication/json
AuthenticationRaw API key in the Authorization header

Request Body

ParameterTypeRequiredDefaultDescription
file_idstringYes-Uploaded image file ID
output_formatstringNopngTransparent output container, png or webp, both with alpha
high_resbooleanNotrueUse 2048 high-resolution inference (on by default, best quality; off = 1024, faster)
output_backgroundbooleanNofalseAlso output the background plate (background layer with the subject area transparent, complementary to the foreground); when on, the response includes background_file_id

Request Example

curl -X POST https://api.ai-mcn.tv:10000/task/image_matting \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"file_id": "537489015178246", "output_format": "png"}'

Success Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "537489015178247",
    "task_type": "image_matting",
    "status": "queued"
  }
}

Query Task Result

Basic Information

ItemValue
Request MethodGET
Request Path/task/image_matting/{task_id}
AuthenticationRaw API key in the Authorization header

Output Result (output_result)

ParameterTypeDescription
file_idstringCutout result file ID (transparent image with alpha)
background_file_idstringBackground plate file ID (subject area transparent; returned only when output_background=true)

Success Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "537489015178247",
    "status": "completed",
    "progress": 100,
    "output_result": {
      "file_id": "537489015178248"
    },
    "create_time": "2026-06-21T08:00:00Z",
    "update_time": "2026-06-21T08:00:03Z"
  }
}

Error Codes

Error CodeHTTP StatusDescriptionResolution
6013400Missing file_idPass the file_id field
6014400File type does not match the taskUpload an image file
6016400Invalid business params (output_format / high_res)Check the parameter ranges
6004404File not foundVerify the file_id
6017400The file is not a recognizable image (for example, a web page saved as .jpg, or a file whose header is cut off). It is rejected at task creation; no task is created and nothing is chargedRe-export the image as JPEG / PNG and upload it again
6502401Authentication failedCheck the Authorization header
6017—The image's actual format can't be read by this API (for example, the extension is .jpg but the content is AVIF); the error message names the actual format (during execution: the task fails and credits are refunded; see error_code in the task result)Convert the image to JPEG / PNG, upload it again and resubmit
6021—The image data is incomplete or damaged, typically truncated by an interrupted download or upload. The file header is intact, so this can't be detected at task creation (during execution: the task fails and credits are refunded; see error_code in the task result)Re-export the image or use the original, then resubmit