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. When true, 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. When alpha_matting is true, mask pixels larger than this value are considered foreground pixels.
  • alpha_matting_background_threshold (integer, optional): Values in [0, 255]. Defaults to 10. When alpha_matting is true, mask pixels smaller than this value are considered background pixels.
  • alpha_matting_erode_size (integer, optional) - Defaults to 10. When alpha_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): When true, background removal was not performed because init_image was found to have violated our terms of service.

Request Examples

$curl -X POST "https://image.octoai.run/background-removal" \
> -H 'Content-Type: application/json' \
> -H "Authorization: Bearer $OCTOAI_TOKEN" \
> -d '{"init_image": "$BASE64_IMAGE_HERE"}'