Image Background Removal API Reference

Image Background Removal

GET/POST /ai/image/cut/out

The Image Background Removal automatically identifies the main object in an image, separates it from the background, and returns the image of main object with white or transparent backgrounds. It provides a variety of background options and custom size selections to optimize product display.

Request Parameters

ParameterTypeRequiredDescription

imageUrl

String

No

The image URL.

Either imageUrl or imageBase64 should be input as request parameter. ImageBase64 is preferred when both imageUrl and imageBase64 exist.

Input image size should be between 100×100 pixels(minimum) and 3000×3000 pixels(maximum).

imageBase64

String

No

The Base64 encoding of the image.

Either imageUrl or imageBase64 should be input as request parameter. ImageBase64 is preferred when both imageUrl and imageBase64 exist.

Input image size should be between 100×100 pixels(minimum) and 3000×3000 pixels(maximum).

backGroundType

String

Yes

The result of image background format. If not be set, it will output transparent background.

Range:

WHITE_BACKGROUND:ouput white background

TRANSPARENT:output transparent background

Sample: WHITE_BACKGROUND

targetWidth

Int

No

Set the width of the output image. After setting, it returns an image with automatically cropped edge blank areas and scaled to the target size. If not, it will output original width without changing the subject's position.

Pixel Range:100-3000

Sample: 800

targetHeight

Int

No

Set the height of the output image. After setting, it returns an image with automatically cropped edge blank areas and scaled to the target size. If not, it will output original height without changing the subject's position.

Pixel Range:100-3000

Sample: 800

Sample Request

IopClient client = new IopClient(url, appkey, appSecret);
IopRequest request = new IopRequest();
request.setApiName("/ai/image/cut/out");
request.addApiParameter("backGroundType", "WHITE_BACKGROUND");
request.addApiParameter("imageBase64", "");
request.addApiParameter("targetHeight", "1000");
request.addApiParameter("imageUrl", "https://ae01.alicdn.com/kf/Sa78257f1d9a34dad8ee494178db12ec8l.jpg");
request.addApiParameter("targetWidth", "800");
IopResponse response = client.execute(request);
System.out.println(response.getBody());
Thread.sleep(10);

Response Parameters

ParameterTypeDescription

resCode

Number

The returned result code, where 200 indicates success. For detailed error codes, please refer to the error code list.

data

Object

The returned result data.

requestId

String

A unique request ID used for troubleshooting.

success

Boolean

The status of the returned request, indicating whether the request was successful.

resMessage

String

The returned request information.

Sample Response

{
  "data": {
    "score": 0.8799999952316284,
    "imageUrl": "http://nhci-image.oss-ap-southeast-1.aliyuncs.com/data%2Fgeneral_matting_online%2FAIDC_AIB_SERVICE%2F7089bce4c9d1469cb552dd225e28a254_202406261430_0.8799999952316284.jpg?OSSAccessKeyId=LTAI5t7WDuqmGKhsCAdMMfuH&Expires=2719383457&Signature=3z8ybSgwj5Tns3LahE%2FJXPh99Tg%3D",
    "usage": 1,
    "width": 800,
    "class": "com.aidc.service.api.client.image.dto.ImageGenResponse",
    "height": 1000
  },
  "requestId": "2101364217193834573077250e647d",
  "success": true,
  "resCode": 200,
  "resMessage": "success",
  "code": "0",
  "request_id": "21015e2217193834573111639",
  "_trace_id_": "2101364217193834573077250e647d"
}

Errors

Error CodeError MessageDescription

500

system error

System error.

501

rate limit exceed

The current interface has reached the current limit. Please contact us via navigation bar or email us (aidge_support@service.alibaba.com) to increase the current limit value.

700

invalid input

The format of the input parameters does not meet the requirements, and resMessage will return detailed fields that do not meet the requirements.

801

model failed

Internal call exception, please contact us via navigation bar or email us (aidge_support@service.alibaba.com) for troubleshooting.

1000

content has sensitive data, please try other input

Content has sensitive data and cannot be handled now. Please try other input.

1001

content control failed, please retry

Content risk failed, please try other input. If an error persists,please contact us via navigation bar or email us (aidge_support@service.alibaba.com) for troubleshooting.

1002

content risk filter failed, please contact us

Content risk filter failed, please contact us via navigation bar or email us (aidge_support@service.alibaba.com) for troubleshooting.

Last updated