Remove Background

POST
Remove background from the given image.

Request

This endpoint expects an object.
alpha_mattingbooleanOptional
True to use alpha matting. May be true only only for rembg driver.
alpha_matting_background_thresholdintegerOptional

Background threshold for alpha matting. Applies only when alpha_matting is true.

alpha_matting_erode_sizeintegerOptional

Erosion size for alpha matting. Applies only when alpha_matting is true.

alpha_matting_foreground_thresholdintegerOptional

Foreground threshold for alpha matting. Applies only when alpha_matting is true.

bgcolorlist of anyOptional
If given, return the foreground pasted onto an image with this background color.
driverstringOptional
Identifies the background removal technique to use. Valid options are rembg or birefnet.
init_imagestringOptional
Input image to modify.
init_image_urlstringOptional

If given, download init_image from this URL.

modelstringOptional

Identifies the model to use for background removal. Valid values depend on the value of the “driver” field. When driver is “birefnet,” model must be “birefnet-dis-epoch540.” When driver is “rembg,” model must be “isnet-general-use”, “u2net”, “u2netp”, “u2net_human_seg”, or “u2net_cloth_seg.”

only_maskbooleanOptional
Flag indicating whether to return only the binary masks.
output_image_encoding"png"Optional
Define which encoding process should be applied before returning the modified image. Only png is accepted.
post_process_maskbooleanOptional
Flag indicating whether to post-process the masks. Applies only when driver is rembg; ignored otherwise.

Response

This endpoint returns an object.
removed_for_safetyboolean
True if the image was removed for safety, False otherwise.
image_b64stringOptional
The modified image or None if it was removed for safety.