图片抠像

自动分离图片主体与背景,输出带透明通道(alpha)的抠像结果,含发丝级软边,可直接用于叠加、封面、海报等合成场景。

效果示例

原图抠像前景(透明)背景底板(主体处透明)
原图抠像前景背景底板

前景层与背景底板互补——两层叠回去即原图;前景可直接用于叠加合成,背景底板(output_background=true 时返回)可作新背景复用。

创建任务

基本信息

项目
请求方法POST
请求路径/task/image_matting
Content-Typeapplication/json
鉴权方式Authorization 请求头(直接传 API Key)

请求参数(Body)

参数名类型必填默认值说明
file_idstring已上传图片文件的 ID
output_formatstringpng透明输出容器,pngwebp,均含 alpha 通道
high_resbooleantrue是否用 2048 高分辨率推理(默认开,质量最佳;关则 1024,更快省显存)
output_backgroundbooleanfalse是否额外输出背景底板(主体处透明的背景层,与前景互补);开启则响应含 background_file_id

请求示例

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"}'

成功响应示例

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

查询任务结果

基本信息

项目
请求方法GET
请求路径/task/image_matting/{task_id}
鉴权方式Authorization 请求头(直接传 API Key)

响应参数(output_result)

参数名类型说明
file_idstring抠像结果文件 ID(带 alpha 的透明图)
background_file_idstring背景底板文件 ID(主体处透明,仅 output_background=true 时返回)

成功响应示例

{
  "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"
  }
}

错误码

错误码HTTP 状态码说明解决方案
6013400file_id 缺失传入 file_id 参数
6014400文件类型与接口不匹配传入图片文件
6016400业务参数非法(output_format / high_res检查参数取值范围
6004404文件不存在检查 file_id 是否正确
6502401鉴权失败检查 Authorization 请求头