Background Removal REST API
Seamlessly remove the background of an image using Background removal API.
OctoAI’s Background Removal API supports models such as IS-NET
.
You need to create an OctoAI Authentication Token to access this API.
How to use
Invoke https://image.octoai.run/background-removal
endpoint with a POST
request.
The headers of the request must include an Authentication Token in the authorization field. The accept header should be set to application/json
to receive the image encoded as base64 in a JSON response.
The only required parameter is init_image
. This is the base64-encoded image whose background needs to removed.
For more details about all parameters, please see the request schema below.
Output
Image with the background removed. The resolution will remain the same as the input image. Using the available parameters, you can change the background color. Additionally, you can also retrieve the mask of the foreground element.
Pricing
*** $0.002*** per API request
Check Pricing Page for more details.
Request Details
Headers:
Authorization
(Required): Your OCTOAI_TOKEN
Content-Type
(Required): Set to application/json
Parameters:
init_image
(string, required): A base64-encoded image whose background should get removed.only_mask
(boolean, optional): Default set to false. When true, return only a single-channel image containing a foreground-background mask. Foreground pixels have values closer to 255, and background pixels have values closer to 0.post_process_mask
(boolean, optional): Default set to true. Whentrue
, apply morphological operations to the mask to smooth it.bgcolor
(list[int], optional): When given, replace background pixels with this color in the output image.alpha_matting
(boolean, optional): Default set to false. If true, apply matting on the alpha channel.alpha_matting_foreground_threshold
(integer, optional): Values in [0, 255]. Defaults to 240. Whenalpha_matting
istrue
, mask pixels larger than this value are considered foreground pixels.alpha_matting_background_threshold
(integer, optional): Values in [0, 255]. Defaults to 10. Whenalpha_matting
istrue
, mask pixels smaller than this value are considered background pixels.alpha_matting_erode_size
(integer, optional) - Defaults to 10. Whenalpha_matting
is true, size of the erosion structure to apply, in pixels.
Response
image_b64
(string): Base64-encoded png containing the processed image.removed_for_safety
(boolean): Whentrue
, background removal was not performed becauseinit_image
was found to have violated our terms of service.