Cars image background removal

FREEMIUM
Verified
By API 4 AI | Updated 4 days ago | Video, Images
Popularity

9.5 / 10

Latency

6,746ms

Service Level

100%

Health Check

100%

Followers: 6
Resources:
Product Website
API Creator:
Rapid account: API 4 AI
API 4 AI
api4ai
Log In to Rate API
Rating: 5 - Votes: 1

README

⭐️ Cars Image Background Removal

Examples API4AI Telegram

This solution is specialized for car images and provides high-accuracy car segmentation and background removal with the option of adding special shadow effects.

This API is created by API4AI. We build our APIs on a completely cloud technology stack which provides full operability, scalability and stable uptime. Our sole goal is to create out-of-the-box self-contained AI solutions that can easily be integrated into any application with just a few simple steps.

Cars image background removal

Features

👉 Features

  • ✅ Removes background from images with cars.
  • ✅ Blurs an area of a car’s license plate.
  • ✅ Returns coordinates of bounding boxes of a car and license plate.
  • ✅ Returns an image of a car over a transparent background or black & white mask.
  • ✅ Optionally adds a realistic shadow.
  • ✅ Optionally blends results with a new background image.
  • ✅ Supports two alternative ways to pass images: as a binary file or via url to a public resource.

👉 Demos


👉 Contacts




🛠 Endpoints

METHOD URL DESCRIPTION
GET https://cars-image-background-removal.p.rapidapi.com/v1/version Get a service version.
GET https://cars-image-background-removal.p.rapidapi.com/v1/modes Get list of available modes.
POST https://cars-image-background-removal.p.rapidapi.com/v1/results Perform image processing and get results.

👉 Get version

Returns an actual version of the service in format vX.Y.Z where X is the version of API.

PROPERTY DESCRIPTION
Endpoint https://cars-image-background-removal.p.rapidapi.com/v1/version
Method GET
Query parameters
POST parameters

Example

curl -X 'GET' 'https://cars-image-background-removal.p.rapidapi.com/v1/version' \
     -H 'X-RapidAPI-Key: ...'
Click here to view the response
v1.3.0



👉 Get list of available modes

The service provides several options for background removal results:

  • fg-image – Image with foreground object (car).
  • fg-mask – Mask of foreground.
  • fg-image-shadow – Image with foreground object (car) with shadow.
  • fg-image-hideclp – Image with foreground object (car) with hidden car license plate.
  • fg-image-shadow-hideclp – Image with foreground object (car) with shadow and hidden car license plate.
PROPERTY DESCRIPTION
Endpoint https://cars-image-background-removal.p.rapidapi.com/v1/modes
Method GET
Query parameters
POST parameters

Example

curl -X 'GET' 'https://cars-image-background-removal.p.rapidapi.com/v1/modes' \
     -H 'X-RapidAPI-Key: ...'
Click here to view the response
[
  "fg-image",
  "fg-image-shadow",
  "fg-image-hideclp",
  "fg-image-shadow-hideclp",
  "fg-mask"
]



👉 Analyze image and return results

Performs actual image analysis and responds with results.

PROPERTY DESCRIPTION
Endpoint https://cars-image-background-removal.p.rapidapi.com/v1/results
Method POST
Query parameters mode
POST parameters image, url, image-bg, url-bg

Passing image

Image can be passed by posting regular “multipart form data” in two alternative ways:

  • as binary file in image field
  • as URL to some public resource in url field

Image must be a regular JPEG or PNG image (with or without transparency).
Usually such images have extensions: .jpg, .jpeg, .png.
The service checks input file by MIME type and accepts the following types:

  • image/jpeg
  • image/png

The size of the image file must be less than 16Mb.

The maximum allowed resolution is 4096x4096.


Passing optional background image

If the background image is passed then it’s content will be blended below foreground object (aligned by the center). The final output image will have the same size as the main input image (not background image!). Meaningless if the mode is fg-mask.

Background image can be passed by posting regular “multipart form data” in two alternative ways:

  • as binary file in image-bg field
  • as URL to some public resource in url-bg field

Image must be a regular JPEG or PNG image (with or without transparency).
Usually such images have extensions: .jpg, .jpeg, .png.
The service checks input file by MIME type and accepts the following types:

  • image/jpeg
  • image/png

The size of the image file must be less than 16Mb.

The maximum allowed resolution is 4096x4096.


Specifying mode

Query parameter mode is optional and may be used to choose the format of the output image: foreground mask or foreground image. Also the foreground image could be returned with shadow under the object and hidden car license plate (if detected).
By default the service uses fg-image.

Available modes and expected content of the resulting image:

  • fg-image (default) – the image with the foreground object (car). Here the result is a 4-channel (RGBA) PNG image where background is transparent.
    • Areas recognized as car will have the same color values at output image as the original input image.
    • Areas recognized as background will be transparent at output image.
    • Pixels of output image near the car borders may be semi transparent.
  • fg-mask – the mask of foreground object (car). In this case the result is a single-channel grayscale PNG image.
    • Areas recognized as foreground (car) will have white color.
    • Areas recognized as background will be black at output image.
    • Pixels of output image near to car borders may have gray values: the closer
      to black, the more likely the pixel is the background.
  • fg-image-shadow – the image with the foreground object (car) and realistic shadow under the car. Image format is as in case of just the foreground object.
  • fg-image-hideclp – the image with the foreground object (car) with hidden license plate. Image format is as in case of just the foreground object.
  • fg-image-shadow-hideclp – the image with the foreground object (car) with realistic shadow and hidden license plate. Image format is as in case of just the foreground object.

Response schema

For responses with 200 HTTP code the type of response is JSON object with the following schema:

{
  "results": [
    {
      "status": {
        "code": ...,
        "message": ...
      },
      "name": ...,
      "md5": ...,
      "page": ...,
      "width": ...,
      "height": ...,
      "entities": [
        {
          "kind": "image",
          "name": ...,
          "image": ...,
          "format": "PNG",
          "representation": "base64"
        },
        {
          "kind": "objects",
          "name": "objects",
          "objects": [...]
        }
      ]
    }
  ]
}

Primary fields:

Name Type Description
results[].status.code string Status code of image processing: ok or failure.
results[].status.message string Human readable explanation for the status of image processing.
results[].name string Original image name passed in request (e.g. my_image.jpg).
results[].md5 string MD5 sum of original image passed in request.
results[].page int Optional page number (presented for multipage inputs only).
results[].width int Optimal image width (presented for valid inputs only).
results[].height int Optional image height (presented for valid inputs only).
results[].entities[].name string The name of the output entity.
results[].entities[].image string PNG result image encoded as base64.
results[].entities[].format string Image format.
  • Entity name. It depends on mode. Examples:

    • cars-fg-image if the output is a foreground object.
    • cars-fg-image-shadow if the output is a foreground object with shadow.
    • cars-fg-image-hideclp if the output is a foreground object with a hidden car license plate (if detected).
    • cars-fg-image-shadow-hideclp if the output is a foreground object with shadow and hidden car license plate (if detected).
    • cars-fg-mask if the output is a foreground mask.
  • The most important part of the response is results[].entities[].image field.

    • Image. The resulting image is a PNG image with transparency.
      Pixels of the original image that are recognized as background will be transparent in the result image.
    • Mask. The result image is a single-channel grayscale PNG image.
      Pixels of the original image that are recognized as background will be black in the resulting image and foreground will be white.

The output image in results[].entities[].image field is encoded as base64.

Other fields that are not described above always have the same values.




📌 Examples


👉 The original image



👉 Just remove the background

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'
Click here to view the response
{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "img.jpg",
      "md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
      "width": 1024,
      "height": 768,
      "entities": [
        {
          "kind": "image",
          "name": "cars-fg-image",
          "image": "iVBORw0KGgoAAAA...YII=",
          "format": "PNG",
          "representation": "base64"
        },
        {
          "kind": "objects",
          "name": "objects",
          "objects": [
            {
              "box": [
                0.138,
                0.37,
                0.6613333333333333,
                0.456
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "classes",
                  "classes": {
                    "opaque-content": 1
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}



👉 Get car’s mask

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-mask' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'
Click here to view the response
{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "img.jpg",
      "md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
      "width": 1024,
      "height": 768,
      "entities": [
        {
          "kind": "image",
          "name": "cars-fg-mask",
          "image": "iVBORw0KGgoAAAA...YII=",
          "format": "PNG",
          "representation": "base64"
        },
        {
          "kind": "objects",
          "name": "objects",
          "objects": [
            {
              "box": [
                0.138,
                0.37,
                0.6613333333333333,
                0.456
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "classes",
                  "classes": {
                    "opaque-content": 1
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}



👉 Blur car’s license plate

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-image-hideclp' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'
Click here to view the response
{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "img.jpg",
      "md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
      "width": 1024,
      "height": 768,
      "entities": [
        {
          "kind": "image",
          "name": "cars-fg-image-hideclp",
          "image": "iVBORw0KGgoAAAA...YII=",
          "format": "PNG",
          "representation": "base64"
        },
        {
          "kind": "objects",
          "name": "objects",
          "objects": [
            {
              "box": [
                0.138,
                0.37,
                0.6613333333333333,
                0.456
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "classes",
                  "classes": {
                    "opaque-content": 1
                  }
                }
              ]
            },
            {
              "box": [
                0.668,
                0.637,
                0.08866666666666667,
                0.064
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "classes",
                  "classes": {
                    "license plate": 0.9868636727333069
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}



👉 Drop shadow under the car and use custom background

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-image-shadow' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg' \
     -F 'image-bg=@bg.png'
Click here to view the response
{
  "results": [
    {
      "status": {
        "code": "ok",
        "message": "Success"
      },
      "name": "img.jpg",
      "md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
      "width": 1024,
      "height": 768,
      "entities": [
        {
          "kind": "image",
          "name": "cars-fg-image-shadow",
          "image": "iVBORw0KGgoAAAA...YII=",
          "format": "PNG",
          "representation": "base64"
        },
        {
          "kind": "objects",
          "name": "objects",
          "objects": [
            {
              "box": [
                0.668,
                0.637,
                0.08866666666666667,
                0.064
              ],
              "entities": [
                {
                  "kind": "classes",
                  "name": "classes",
                  "classes": {
                    "opaque-content": 1
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}




❗️ Possible errors


👉 The service can not process an image

When a client sends an image that can not be processed for some reason(s), the service responds with 200 code and returns a JSON object in the same format as the format for successful analysis. In this case, the results[].status.code will have failure value and results[].status.message will contain relevant explanation.

Example of possible reasons for the issue:

  • Unsupported MIME type
  • Image resolution exceeds limits
  • Corrupted image

Example response for image with unsupported MIME type:

{
  "results": [
    {
      "status": {
        "code": "failure",
        "message": "Can not load image."
      },
      "name": "file.txt",
      "md5": "d41d8cd98f00b204e9800998ecf8427e",
      "entities": []
    }
  ]
}

Example response for image with the resolution too big to process:

{
  "results": [
    {
      "status": {
        "code": "failure",
        "message": "Resolution is too big: 6000x4000. Max allowed resolution: 4096x4096."
      },
      "name": "24mpx.jpg",
      "md5": "a24c7cd77e21b303a1211889cea7527b",
      "entities": []
    }
  ]
}

👉 Request size is too big

Request size is limited by approximately 32Mb.
When a client sends a request that exceeds this limit, the service responds with 413 code.

The typical reason for exceeding this limit is an overly large image.
Taking into account additional HTTP overhead, we strongly recommend not passing image files of size more than 16Mb.

Example response for overly big image:

Error: Request Entity Too Large

Your client issued a request that was too large.

👉 Missing image

When a client sends a request without an image, the service responds with 422 code and returns a JSON object.

Example response for request with missing image:

{"detail":"Missing image or url field."}




❓ F.A.Q.


👉 How to pass an image as binary file?

Post a file content as a “multipart form data” field named image.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'

👉 How to pass an image as URL?

Post a URL to file as a “multipart form data” field named url.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'url=https://storage.googleapis.com/api4ai-static/rapidapi/cars-image-background-removal/car.jpg'

👉 How to get a car’s segmentation mask?

Use mode=fg-mask query parameter.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-mask' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'

👉 How to drop shadow under the car?

Use mode=fg-image-shadow query parameter.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-image-shadow' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'

👉 How to blur a car’s license plate area?

Use mode=fg-image-hideclp query parameter.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-image-hideclp' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'

👉 How to drop shadow and blur a car’s license plate area simultaneously?

Use mode=fg-image-hideclp query parameter.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results?mode=fg-image-shadow-hideclp' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg'

👉 How to pass a custom background image as binary file?

Post a file content as a “multipart form data” field named image-bg.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg' \
     -F 'image-bg=@bg.jpg'

👉 How to pass a custom background image as URL?

Post a file as a “multipart form data” field named url-bg.

curl -X 'POST' 'https://cars-image-background-removal.p.rapidapi.com/v1/results' \
     -H 'X-RapidAPI-Key: ...' \
     -F 'image=@img.jpg' \
     -F 'url-bg=https://storage.googleapis.com/api4ai-static/rapidapi/cars-image-background-removal/bg.png'

👉 I’ve got JSON response. Where is the resulting image???

The resulting png image is a part of JSON response and encoded as base64 string. Property path: results[].entities[].image

{
  "results": [
    {
      ...
      "entities": [
        {
          "kind": "image",
          "image": RESULTING-PNG-IMAGE-ENCODED-AS-BASE64-STRING,
          ...
        }
        ...
      ]
    }
  ]
}

👉 Where to find code examples?

Code examples in Python, C#, JavaScript, Swift and other popular programming languages: https://gitlab.com/api4ai/examples/img-bg-removal-cars


👉 Where to try live demo?


👉 I need support

Feel free to contact API4AI team if you have any questions.