
LEIA-ME
Overview
The service processes an input image and responds with the output “foreground” image.
There are three options of output image:
- Mask of foreground. In this case the result is single-channel grayscale PNG image.
- Areas recognized as foreground will have white color.
- Areas recognized as background will be black at output image.
- Pixels of output image near to object borders may have gray values: the closer
to black, the more likely the pixel is the background.
- The image with the foreground object. The result is 4-channel (
RGBA
) PNG image where background is transparent.- Areas recognized as foreground will have the same color values at output image as original input image.
- Areas recognized as background will be transparent at output image.
- Pixels of output image near the object borders may be semitransparent.
- The image with the foreground object and shadow. The result is very similar to previous one (foreground object) but contains additional black shadow region in the bottom of object.
Endpoints
METHOD | URL | DESCRIPTION |
---|---|---|
GET | https://background-removal4.p.rapidapi.com/v1/version |
Get service version. |
GET | https://background-removal4.p.rapidapi.com/v1/modes |
Get list of available modes. |
POST | https://background-removal4.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://background-removal4.p.rapidapi.com/v1/version |
Method | GET |
Query parameters | – |
POST parameters | – |
Examples
Request:
$ curl -X 'GET' 'https://background-removal4.p.rapidapi.com/v1/version'
Response:
v1.5.0
Get list of available modes
The service provides two options for background removal results:
- Mask of foreground.
- Image with foreground object.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://background-removal4.p.rapidapi.com/v1/modes |
Method | GET |
Query parameters | – |
POST parameters | – |
Examples
Request:
$ curl -X 'GET' 'https://background-removal4.p.rapidapi.com/v1/modes'
Response:
[
"fg-image",
"fg-image-shadow",
"fg-mask"
]
Analyse image and return results
Performs actual image analysis and responds with results.
PROPERTY | DESCRIPTION |
---|---|
Endpoint | https://background-removal4.p.rapidapi.com/v1/results |
Method | POST |
Query parameters | mode |
POST parameters | image , url |
Query parameter mode
is optional and may be used to choose format of output image: foreground mask or foreground image or foreground image with shadow.
By default the service uses fg-image
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": ...,
"entities": [
{
"kind": "image",
"name": ...,
"image": ...,
"format": "PNG"
}
]
}
]
}
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 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[].entities[].name |
string |
The name of output entity. |
results[].entities[].image |
string |
PNG result image encoded as base64. |
results[].entities[].format |
string |
Image format. |
-
Entity name. There are three possible names:
general-fg-image
if the output is foreground object.general-fg-image-shadow
if the output is foreground object with shadow.general-fg-mask
if the output is foreground mask.
-
The most important part of the response is
results[].entities[].image
field.- Image. The result image is PNG image with transparency.
Pixels of original image that are recognized as background will be transparent in the result image. - Mask. The result image is single-channel grayscale PNG image.
Pixels of original image that are recognized as background will be black in the result image and foreground will be white.
- Image. The result image is PNG image with transparency.
The output image in results[].entities[].image
field is encoded as base64.
Other fields that are not described above always have the same values.
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 image file must be less than 16Mb
.
The maximum allowed resolution is 4096x4096
.
Examples
Request:
curl -X 'POST' 'https://background-removal4.p.rapidapi.com/v1/results' -F 'image=@img.jpg'
Response:
{
"results": [
{
"status": {
"code": "ok",
"message": "Success"
},
"name": "img.jpg",
"md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
"entities": [
{
"kind": "image",
"name": "general-fg-image",
"image": "iVBORw0KGgoAAAA...YII=",
"format": "PNG"
}
]
}
]
}
Request:
curl -X 'POST' 'https://background-removal4.p.rapidapi.com/v1/results?mode=fg-mask' -F 'image=@img.jpg'
Response:
{
"results": [
{
"status": {
"code": "ok",
"message": "Success"
},
"name": "img.jpg",
"md5": "f2d13d0242b98aae82bc7a6dc76e1ea9",
"entities": [
{
"kind": "image",
"name": "general-fg-mask",
"image": "iVBORw0KGgoAAAA...YII=",
"format": "PNG"
}
]
}
]
}
Possible errors
The service can not process an image
When client sends an image that can not be processed for some reason(s), the service responds with 200
code and returns 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 file MIME type
- Corrupted image
- File passed as URL is too big or non downloadable
Example response for corrupted image:
{
"results": [
{
"status": {
"code": "failure",
"message": "Can not load image."
},
"name": "file.jpg",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"entities": []
}
]
}
Request size is too big
Request size is limited by approximately 32Mb
.
When client sends request that exceeds this limit, the service responds with 413
code.
The typical reason for exceeding this limit is overly large image.
Taking into account additional HTTP overhead, we strongly recommend to not pass image files of size more than 16Mb
.
Example response for too big request:
Error: Request Entity Too Large
Your client issued a request that was too large.
Missing image or url
When client sends a request without an image and url, the service responds with 422
code and returns JSON object.
Example response for request without image or url:
{"detail": "Missing image or url field."}