Smart Matting automatically identifies an image's salient subject, separates it from the background, and returns an image of the subject with the background removed. It also offers multiple background options and custom dimension settings to enhance product presentation. This is a synchronous API.
Use cases
Enable secondary editing of assets: After separating the subject from the background, you can edit the image further.
Improve asset processing efficiency: Quickly extract subjects from various source images for easier background replacement, accelerating the creation of ad visuals and marketing posters.
If you need to chain multiple operations like matting, translation, erasing, and outpainting into a single workflow, we recommend using Smart Layout for orchestration. This API serves as an independent atomic capability.
Features
1. Precise subject recognition
AI-powered automatic recognition: Uses a deep learning model to intelligently distinguish between foreground subjects (such as people, products, or objects) and the background, eliminating the need for manual outlining.
Adaptable to multiple scenarios: Achieves high-precision segmentation for complex scenes, including fine details like hair strands, transparent objects, and fuzzy edges, with an accuracy of over 95%.
2. Intelligent edge optimization
Fine-detail processing: Automatically refines edge aliasing and semi-transparent areas, such as smoke or glass, to ensure natural transitions.
3. Multiple output formats and background controls
Transparent background export: Generates images with a transparent background (PNG) or a white background, suitable for e-commerce and design applications.
Custom background colors: Allows you to specify a custom color for the background.
Before and after
Original image (input) | Result image (output) |
|
|
|
|
|
|
Endpoint
POST /rest/ai/image/mattingFor complete request signing instructions, SDK examples in multiple languages including Java, Python, and Go, and online debugging, see the Alibaba Cloud OpenAPI Developer Portal: Smart Matting API (OpenAPI Portal).
Request parameters
Parameter | Type | Required | Description |
| String | Yes | The background format for the output image: |
| String | Yes | The URL of the source image. Requirements: JPG, JPEG, PNG, BMP, or WEBP format; resolution between 100×100 and 3000×3000 pixels; file size ≤ 10 MB. |
| Number | No | The desired output width in pixels. Valid values: 100 to 5000. If specified, the service automatically crops blank margins and scales the image. If omitted, the image retains its original width and the subject's position remains unchanged. |
| Number | No | The desired output height in pixels. Valid values: 100 to 5000. If specified, the service automatically crops blank margins and scales the image. If omitted, the image retains its original height and the subject's position remains unchanged. |
| String | No | A custom background color specified as a BGR triplet (note: BGR, not RGB), separated by commas. For example, |
Response fields
Parameter | Type | Description |
| String | The business status code. |
| String | The unique request ID. Provide this ID when contacting technical support for assistance. |
| String | The response message. On success, the value is |
| Boolean | Indicates whether the call was successful. |
| Object | The returned result object. |
| String | A signed OSS URL for the processed image. The result is a transparent PNG if |
| Number | A quality score for the matting result. Higher scores indicate greater reliability. |
| Number | The width of the output image in pixels. |
| Number | The height of the output image in pixels. |
| Object | Contains layer information, including the original image URL, the matting result URL, and matting region details. |
| Object | The usage information. |
| Number | The number of images processed. |
Complete example
Request example
{
"ImageUrl": "https://sc02.alicdn.com/kf/H09364d2c7fc942e685d3b0f656261b24Q.png",
"BackGroundType": "WHITE_BACKGROUND",
"TargetWidth": 800,
"TargetHeight": 800,
"BgColor": "255,255,255"
}Response example
{
"Data": {
"ImageUrl": "http://dashscope-7c2c.oss-cn-shanghai.aliyuncs.com/7d/4a/20260525/f3547444/52033655bd054737960a87518655d935_202605251926_5.959999978542328.jpg?Expires=1782300370&OSSAccessKeyId=LTAI5tPxpiCM2hjmWrFXrym1&Signature=XskJ9GEdikVhbBz7DfgbESj5xJ0%3D",
"Score": 5.959999978542328,
"Height": 800,
"UsageMap": {
"ProcessedImageCount": 1
},
"Width": 800,
"structData": {
"message": {
"matting_results": {
"origin_url": "https://img.alicdn.com/imgextra/i3/O1CN01nG4vzu2AIxB7YWE9O_!!6000000008181-0-tps-1500-1500.jpg",
"score": "0.8999999761581421",
"file": "data/general_matting_online/nhci_aigc/c21baea1df714751a02beed6f1a94602_202610211757_0.8999999761581421.png",
"extra_info": "",
"pass": "0",
"bbox": "102,377,1500,1253",
"plain_url": "http://aib-image.oss-ap-southeast-1.aliyuncs.com/data%2Fgeneral_matting_online%2Fnhci_aigc%2Fc21baea1df714751a02beed6f1a94602_202610211757_0.8999999761581421_plain.png?OSSAccessKeyId=LTAI5t75Zk154w1Ne1UmpHKJ&Expires=2792576662&Signature=5%2FCVs88ORcu724fV9XPDtgd%2Bl6E%3D",
"image_shape": [
1500,
1500
],
"url": "http://aib-image.oss-ap-southeast-1.aliyuncs.com/data%2Fgeneral_matting_online%2Fnhci_aigc%2Fc21baea1df714751a02beed6f1a94602_202610211757_0.8999999761581421.png?OSSAccessKeyId=LTAI5t75Zk154w1Ne1UmpHKJ&Expires=2792576662&Signature=IbR7G6lF2eK0oQQEDVqaF2yKEK0%3D"
},
"status_info": {
"code": 0,
"message": ""
}
}
}
},
"RequestId": "7BEDF90E-D04E-1430-BDAE-18A31F84A348",
"Message": "Success",
"Code": "success",
"Success": true
}Recommendations
Transparent vs. white background: For e-commerce product images that require a white background, pass
WHITE_BACKGROUND. For secondary composition (such as adding a marketing background), we recommend passingTRANSPARENTfor greater flexibility in client-side processing.Resolution and quality: The closer the source image resolution is to the 3000×3000 pixel limit, the finer the details of edges like hair or transparent objects will be. For very small images (such as 100×100 pixels), we recommend upscaling them before matting.
Color channel order: The
BgColorparameter uses BGR order, not the more common RGB. Ensure you convert the format when porting code from libraries other than OpenCV.Quality score: A low
Scoreusually indicates that the source image is too complex (for example, a solid-colored product against a solid-colored background). In such cases, we recommend manual review or using a different source image.
Error codes
Error code | Description |
|
|
| The input image is blocked by content moderation. |
| Failed to download the image, or a downstream vision model is temporarily unavailable. Retry the request using an exponential backoff strategy. |
| You have exhausted your free trial quota. To continue, purchase a resource plan or disable the "stop when quota is exhausted" setting. |
| An internal server-side error occurred. Please save the |
For a complete list of error codes, see Error Codes.
Limitations
Invocation mode: This is a synchronous API with a default QPS of 5 and a 30-second request timeout.
Input image: JPG, JPEG, PNG, BMP, or WEBP format. Resolution must be between 100×100 and 3000×3000 pixels. File size must be 10 MB or less.
Output: The service outputs a JPG for solid backgrounds or a PNG with an alpha channel for transparent backgrounds. The result is delivered as a signed OSS URL in the
Data.ImageUrlfield, which is typically valid for 7 days.Billing: $0.0005 per image, charged based on the
ProcessedImageCountfield. For details, see Material Optimization Billing.





