Background Remover API Overview

The Background Remover (BGR) API, utilizing advanced AI, enables users to remove the background on any vehicle image provided. The output of this API can serve as a valuable complement to the information provided in a car report.

To access the API for the BGR images, you must have an API-enabled account, which will provide you with an API Key. This Key allows your application to send data transfer requests to the VinAudit API servers.

Supported Methods of Image Input
  1. Passing Image URL: Requires a publicly accessible URL pointing to the image. This method is convenient for images already hosted online.
  2. Passing Image File: Allows the direct upload of image files (jpg, png) from the client’s system. This method is suitable for images stored locally on the user’s device.
  3. Passing Base64 Image: Involves sending the image as a Base64-encoded string. This method is beneficial for applications that process images in a format that can be easily encoded and transmitted within JSON structures.
Background Manipulation Options
  1. White Background: Replace the original background with a plain white background.
  2. Transparent Background: Makes the original background transparent.
  3. Custom Background: Allows the user to upload a custom background image that replaces the original background. For operations requiring a custom background, the user must pass a publicly accessible URL or upload a file for the custom background.

*Output will also include ‘window correction’ which will remove any objects in the background that appear through a window such as a building, trees, other vehicles, etc.

API Endpoints
  1. For image URLs: http://api-bgremover.vinaudit.com/remove-bg-url
  2. For image file uploads: http://api-bgremover.vinaudit.com/remove-bg-upload
  3. For Base64 encoded images: http://api-bgremover.vinaudit.com/remove-bg-base64
API Endpoint 1 - Through a URL (http://api-bgremover.vinaudit.com/remove-bg-url)
Parameter Description Optional Examples
image_url Url of vehicle, must be publicly accessible. no https://hips.hearstapps.com/hmg-prod/images/p90475606-highres-rolls-royce-phantom1677268219.jpg?crop=0.663xw:0.496xh;0.136xw,0.372xh&resize=1200:*
key Your VinAudit API key no YOUR_VA_KEY
background white or transparent or custom (uploaded image) yes white
background_url Public accessible url of custom background yes https://img.freepik.com/free-photo/vintage-grunge-blue-concrete-texture-studio-wall-background-with-vignette_1258-28395.jpg
center_output center the output or not yes true
crop_output crop the output or not yes true
shadow add shadow to output or not yes true
custom_background Use this to pass a local system file for custom background. yes open('custom_background_sample.jpg', 'rb')
API Endpoint 2 - Through Base64 of an image (http://api-bgremover.vinaudit.com/remove-bg-base64)
Parameter Description Optional Examples
image_data base64 encoded string of vehicle image no data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAzIAAAJpCAYAAAB2CwetAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAP+lSURBVHhe7P1nsyRZkp4JqnN2ebDMSF5Z1VXdDTSABRoNOoPBEACzH1dkv4zIft2/gV+1sjsiWBmRFcjOYjAD2mheJCtp8Eudu+/76DG71/yYXTdzjxuRkVWuEeea2SGqevQcM9PXD7Hax598srR3mbbS7u1V6e0ar5Yc3zGq3bFehUZ9t7tpoDU6fo/
key Your VinAudit API key no YOUR_VA_KEY
background white or transparent or custom (uploaded image) yes white
background_url Public accessible url of custom background yes https://img.freepik.com/free-photo/vintage-grunge-blue-concrete-texture-studio-wall-background-with-vignette_1258-28395.jpg
center_output center the output or not yes true
crop_output crop the output or not yes true
shadow add shadow to output or not yes true
custom_background Use this to pass a local system file for custom background. yes open('custom_background_sample.jpg', 'rb')
API Endpoint 3 - Upload an image directly (http://api-bgremover.vinaudit.com/remove-bg-upload)
Parameter Description Optional Examples
image_file Image file in png or jpg format no
key Your VinAudit API key no YOUR_VA_KEY
background white or transparent or custom (uploaded image) yes white
background_url Public accessible url of custom background yes https://img.freepik.com/free-photo/vintage-grunge-blue-concrete-texture-studio-wall-background-with-vignette_1258-28395.jpg
center_output center the output or not yes true
crop_output crop the output or not yes true
shadow add shadow to output or not yes true
custom_background Use this to pass a local system file for custom background. yes open('custom_background_sample.jpg', 'rb')
Response elements
Element Description Example
output_url The API returns a URL of the output image which users can open on any browser. https://getcarimages.com/bg-uploads/d4ce89c59177882cc03406bd9708b6e79b2.jpg
success Whether execution was successful or not.
One of:
true: Background is successfully removed
false: An error occurred during the execution
true
message This will be present in case any error occurs. It will contain a brief about the cause of the error. "Invalid Key"
Brief on Image Processing Options
  1. background: It can take “white_background”, “custom_background” & “transparent_background” to modify the background of the final output.
  2. background_url: Public accessible URL of custom background.
  3. center_output: It can take “true” or “false”. It centers the position of the output
  4. crop_output: It can take “true” or “false”. Crops the final output to fit the new background more closely. Only one of the parameters “crop_output” or “center_output” can be set to True.
  5. shadow: It can take “true” or “false”. It allows users to add shadow to output, giving it a more natural and integrated appearance with the new background.
  6. custom_background: You can pass a file from your local system in the byte format of custom background. In the case of both ‘background_url’ and ‘custom_background’ preference will be given to ‘background_url’ .
Python Code Snippets for Sending API Request
For Image URL API
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import requests
import json

url = "https://stimg.cardekho.com/images/carexteriorimages/930x620/Rolls-Royce/Spectre/11100/1705661590820/front-left-side-47.jpg"
req_json = {
    "image_url": url,  ##URL Must be publically accessible
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "white_background",  ##It can take "white_background", "custom_background" & "transparent_background"
    "center_output": False,  ##Whether to center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ###Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}
response = requests.post(api_url, data=req_json)
print(response.json())
For Image File API
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import requests
import json

req_json = {
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "white_background",  ##It can take "white_background", "custom_background" &
    "transparent_background" "background_url": "",
    "center_output": False,  ##This will center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ##Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}
files = {
    "image_file": open("/PATH/TO/TEST_IMAGE.jpg", "rb")
}  ##Assuming your local file name is test.jpg
api_file_url = "http://api-bgremover.vinaudit.com/remove-bg-upload"
response = requests.post(api_file_url, data=req_json, files=files)
print(response.text)
Give a Custom Background
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import requests
import json

url = "https://stimg.cardekho.com/images/carexteriorimages/930x620/Rolls-Royce/Rolls-Royce-Phantom/7783/1587206758888/front-left-side-47.jpg"
req_json = {
    "image_url": url,  ##URL Must be publically accessible
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "custom_background",  ##It can take "white_background", "custom_background" &
    "transparent_background"
    "background_url": "http://api-bgremover.vinaudit.com/getImage/5c629c7b5a66e13b5b1426a0f1acb0308dc.png",  ##URL of custom background
    "center_output": False,  ##This will center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ##Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}
api_url = "http://api-bgremover.vinaudit.com/remove-bg-url"
response = requests.post(api_url, data=req_json)
print(response.json())
For Base64 Encoded String API
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import requests
import json
import base64

file_name = "test_image2.jpg"  ##Assuming your local file name is test.jpg
with open(file_name, "rb") as file:
    encoded_string = base64.b64encode(file.read())
req_json = {
    "image_data": encoded_string,  ###This is base64 Encoded string of source image
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "white_background",  ##It can take "white_background", "custom_background" & "transparent_background"
    "background_url": "https://img.freepik.com/free-photo/vintage-grunge-blue-concrete-texture-studio-wall-background-with-vignette_1258-28395.jpg",
    "center_output": False,  ##This will center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ##Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}
api_base64_url = "http://api-bgremover.vinaudit.com/remove-bg-base64"
response = requests.pos
For Using local file for Custom Background
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
import json
import base64

req_json = {
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "custom_background",  ##It can take "white_background", "custom_background" & "transparent_background"
    "center_output": False,  ##This will center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ##Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}

files = {
    "image_file": open("/home/PATH/TO/LOCAL/FILE/test_image2.jpg", "rb"),
    "custom_background": open(
        "/home/PATH/TO/LOCAL/FILE/custom_background_sample.jpg", "rb"
    ),
}

api_url = "http://api-bgremover.vinaudit.com/remove-bg-upload"
response = requests.post(api_url, files=files, data=req_json)
print(response.text)
Saving Output
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
import json

url = "https://stimg.cardekho.com/images/carexteriorimages/930x620/Rolls-Royce/Spectre/11100/1705661590820/front-left-side-47.jpg"
req_json = {
    "image_url": url,  ##URL Must be publically accessible
    "key": "YOUR_KEY",  ##KEY to access API
    "background": "white_background",  ##It can take "white_background", "custom_background" &
    "transparent_background"
    "center_output": False,  ##Whether to center the output image
    "shadow": True,  ##Whether to have a shadow in the resulting image or not
    "crop_output": False,  ###Whether to crop to final output, only one of 'center_output' or 'crop_output' can be used
}
api_url = "http://api-bgremover.vinaudit.com/remove-bg-url"
response = requests.post(api_url, data=req_json)
print(response.json())
saving_file_name = "output_sample.png"  ##set saving file name
api_decoded_response = json.loads(response.content.decode("utf-8"))
api_output_url = api_decoded_response["output_url"]
output_image = requests.get(api_output_url)
with open(f"{saving_file_name}", "wb") as f:
    f.write(output_image.content)