Skip to main content

Image to Mask


Image to Mask

POST https://api.novita.ai/v3/img2mask

Transform an image into its corresponding mask.

Request header parameters

  • Content-TypestringRequired

    undefined

    Enum:
    application/json
  • AuthorizationstringRequired

    Bearer authentication format, for example: Bearer {{API Key}}.

Request Body parameters

  • extraobject

    Optional extra parameters for the request.

    Show properties
  • image_filestringRequired

    The base64 of original image, with a maximum resolution of 2048 * 2048 and a max file size of 30 Mb.

Responses

  • masks[object]

    undefined

    Show properties

Example

This API helps to convert an image into a corresponding mask.

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

Request:

curl --location 'https://api.novita.ai/v3/img2mask' \
--header 'Authorization: Bearer {{key}}' \
--header 'Content-Type: application/json' \
--data '{
    "image_file": "{{Base64 encoded image}}"
}'

Origin Image:

novita.ai API

HTTP status codes in the 2xx range indicate that the request has been successfully accepted, code 400 means requst params error, while status codes in the 5xx range indicate internal server errors.

You can get mask image_file in masks of response.

Mask Image:

novita.ai API
novita.ai API
novita.ai API
novita.ai API
novita.ai API

Response:

{
    "masks": [
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                0,
                0,
                1023,
                958
            ],
            "area": 304278
        },
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                274,
                114,
                448,
                909
            ],
            "area": 281126
        },
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                5,
                36,
                354,
                987
            ],
            "area": 138738
        },
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                284,
                491,
                435,
                391
            ],
            "area": 79647
        },
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                332,
                512,
                284,
                511
            ],
            "area": 77496
        },
        {
            "image_file": "{{Base64 encoded mask}}",
            "image_type": "png",
            "bbox": [
                688,
                683,
                319,
                340
            ],
            "area": 71202
        }
    ]
}