Skip to content

Remove Background

PRICING DEMO

This page describes API for removing background for images. The service is great for removing background from product photos as well as photos of generic items and people. The API follows the general rules of Ximilar API as described in Section First steps.

This service API has two endpoints running at URLs:

https://api.ximilar.com/removebg/precise/removebg
https://api.ximilar.com/removebg/fast/removebg

Activate and try the service in Ximilar App

In order to get access to the Remove Background service, please register at https://app.ximilar.com and then click on this Service on the main panel to make it accessible for your Ximilar account.

RemoveBG endpoint: /precise/removebg and /fast/removebg

Given a list of image records, this method removes backgrounds for each of them. The result images with removed background are stored temporarily for 24h in _output_url_mask, _output_url_whitebg, and _output_url fields of json records. You can download them and use it for your use case.

Parameters:

  • records: list of photos to upscale for
    • must contain either of _url or _base64 field - see section image data for details
    • binary_mask (optional, boolean) - if true, _output_url_mask field with url to .jpg image of binary mask will be included in response
    • white_background (optional, boolean) - if true, _output_url_whitebg field with url to .jpg image with white background will be included in response
  • image_format - Optional field (string), if not specified it will convert _output_url to png and _output_url_mask to jpg. Available options png, jpg, webp.
  • image_quality - Optional field (int), default is 85.

$ curl https://api.ximilar.com/removebg/precise/removebg -H "Content-Type: application/json" -H "Authorization: Token __API_TOKEN__" -d '{
    "records": [
        { "_url": "https://bit.ly/2IymQJv",
          "binary_mask": true,
          "white_background": true
         }
    ]
}'

Returns:

  • HTTP error code 2XX, if the method was OK and other HTTP error code, if the method failed.
  • Body of the response is a JSON object (map) with the following fields:
    • status - a JSON map with a status of the method processing. It contains these subfields:
      • code - a numeric code of the operation status; it follows the concept of HTTP status codes (2XX, 4XX). Specific codes are described for each type of answer (or operation) (see below).
      • text - a text describing the status code
      • error_description - in case of the processing ended with error (codes 4XX), this field contains a detailed description of the error; this might include Java stack traces.
    • Example of statuses that can be returned:
      "status": {"code": 200, "text": "OK"}
      "status": {"code": 402, "text": "aborted by error", error_description="..."}
      "status": {"code": 500, "text": "unknown error", "error_description": "..."}
    • statistics - a map of various statistics about the processing. The only statistic included every time is
      • processing time - time of actual processing of the query [in seconds]
    • records - JSON array with the input records, each record enriched by field _output_url_mask, _output_url_whitebg, and _output_url with url path to the corresponding image. These images are available for download for 24 hours.
CLICK TO SHOW JSON RESULT

{
  "records": [
    {
      "_status": {
        "code": 200,
        "text": "OK",
        "request_id": "62e777b4-d7ad-458c-8de7-08fb173cfa2e"
      },
      "_id": "60802523-4cbe-48ca-8597-b0f79829ddfb",
      "_width": 1380,
      "_height": 868,
      "_output_url": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/94aaae31-98bc-49f5-a4ed-114f8bf0c590.png",
      "_output_url_mask": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/8e4b5af6-3210-4417-b0ef-14c2384904c8.jpg",
      "_output_url_whitebg": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/52598d95-552b-4450-b4a5-6ab752b24f09.jpg"
    }
  ],
  "status": {
    "code": 200,
    "text": "OK",
    "request_id": "62e777b4-d7ad-458c-8de7-08fb173cfa2e",
    "proc_id": "43b577c7-d392-4bc8-b1cf-cae92b196691"
  },
  "statistics": {
    "processing time": 1.4223403930664062
  }
}