Skip to main content

Enterprise: Background Removal and Create mask Endpoint

Overview

This endpoint removes background from image and create mask.

removebg-createmask endpoint result
caution

Make sure you add your s3 details for image_editing server, so you can receive image generated in your bucket. Images generated without s3 details being added will be delete after 24hours

Request

--request POST 'https://modelslab.com/api/v1/enterprise/image_editing/removebg_mask' \

Make a POST request to https://modelslab.com/api/v1/enterprise/image_editing/removebg_mask endpoint and pass the required parameters as a request body to the endpoint.

Body Attributes

ParameterDescription
keyYour API Key used for request authorization
imageurl of the image you want to remove and create its mask
alpha_mattingWhether to perform alpha matting. It accepts true or false. Default is false
post_process_maskTo post process the mask image. It accepts true or false. Default is false
only_maskWhether to return only mask image or not. It accept true or false. Default is false
seedSeed is used to reproduce results, same seed will give you same image in return again. Pass null for a random number.
alpha_matting_foreground_thresholdOptional. Threshold for alpha matting foreground. Default is 240
alpha_matting_background_thresholdOptional. Threshold for alpha matting foreground. Default is 20
alpha_matting_erode_sizeOptional. Erode size for alpha matting. Default is 5.
webhookSet an URL to get a POST API call once the image generation is complete.
track_idThis ID is returned in the response to the webhook API call. This will be used to identify the webhook request.

Example

Body

Body
{
"key":"",
"seed":12345,
"image":"https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy.png",
"post_process_mask": false,
"only_mask": false,
"alpha_matting":false,
"webhook": null,
"track_id": null
}

Request

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
"key":"",
"seed":12345,
"image":"https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy.png",
"post_process_mask": false,
"only_mask": false,
"alpha_matting":false,
"webhook": null,
"track_id": null
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

fetch("https://modelslab.com/api/v1/enterprise/image_editing/removebg_mask", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Response

Example Response

{
"status": "success",
"generationTime": 4.726040601730347,
"id": 558,
"output": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2a231897-80f8-4cdd-82bf-e0d43e82462d.png.png"
],
"meta": {
"alpha_matting": "0",
"alpha_matting_background_threshold": 20,
"alpha_matting_erode_size": 5,
"alpha_matting_foreground_threshold": 240,
"base64": "no",
"file_prefix": "2a231897-80f8-4cdd-82bf-e0d43e82462d.png",
"image_url": "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy.png",
"instant_response": "no",
"only_mask": false,
"outdir": "out",
"post_process_mask": "0",
"seed": 1,
"temp": "no"
}
}