Polygon

Polygons are useful for instance segmentation tasks where you want to have a tighter outline than a bounding box can offer. You may use polygons instead of segmentation tools because the target objects have easy-to-label vertices.

Import

Python SDK

Polygon is a type of ObjectAnnotation

Definition

Polygon(points=list(Points(x,y))

ParameterValue
pointsList of Points

Supported data types

Data typeSupported
Image, GeospatialYes
ObjectAnnotation(
  name = "polygon",
  value = Polygon(points=[Point(x=10, y=10), Point(x=0, y=10), Point(x=10, y=10)]),
)
## Coordinates in the desired EPSG coordinate system
polygon_points = list([Point(x=-99.21052827588443, y=19.405662413477728), Point(x=-99.20534818927473, y=19.400498983095076), Point(x=-100.505348189274754, y=29.400498983095045)])

ObjectAnnotation(
  name = "polygon_geospatial",
  value = Polygon(points=polygon_points),
)

Format convertors

MethodUsageComments
from_shapely()Polygon.from_shapely(shapely_object)Transforms a shapely object. Learn more about shapely

NDJSON

NDJSON format is recommended if an annotation type is not yet supported in Python SDK or if you are unable to use the Python environment.

Definition

ParameterAsset typeRequiredDescription
uuidImage

Tiled imagery
YesA user-generated UUID for each annotation. If you import an annotation to a Data Row and there is already an imported annotation with the same uuid on that Data Row, the latest import will override the previous one. The uuid must be 128 bits (32 characters). The following formats are supported:

- A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11

- {a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}

- a0eebc999c0b4ef8bb6d6bb9bd380a11

- a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11

- {a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}
schemaIdImage

Tiled imagery
YesThe ID of the schema that contains all of the information needed for rendering your annotation.
dataRow.idImage

Tiled imagery
YesThe ID of the Data Row where you want to attach the imported annotations.
polygon.xImage

Tiled imagery
Yesx-coordinate for a single point on the Polygon annotation. For Tiled imagery, this value is the longitude.
polygon.yImage

Tiled imagery
Yesy-coordinate for a single point on the Polygon annotation. For Tiled imagery, this value is the latitude.

Supported data types

Data typeSupported
Image, GeospatialYes

Format

{
    "uuid": "1b5762e9-416c-44cf-9a5f-07effb51f863",
    "schemaId": "ck67grts29n7y0890q89jdcyp",
    "dataRow": {
        "id": "cjxav4aa07r1g0dsq70t9eveg"
    },
    "polygon": [
        {
            "x": 2,
            "y": 99
        },
        {
            "x": 93,
            "y": 5
        },
        {
            "x": 51,
            "y": 106
        },
        {
            "x": 176,
            "y": 142
        }
    ]
}
{
    "uuid": "1b5762e9-416c-44cf-9a5f-07effb51f863",
    "schemaId": "ck67grts29n7y0890q89jdcyp",
    "dataRow": {
        "id": "cjxav4aa07r1g0dsq70t9eveg"
    },
    "polygon": [
        {
            "x": -99.21052827588443,
            "y": 19.405662413477728
        },
        {
            "x": -99.20534818927473,
            "y": 19.400498983095076
        },
        {
            "x": -100.505348189274754,
            "y": 29.400498983095045
        }
    ]
}

Export

When you export your Polygon annotations from Labelbox, the export file will contain the following information for each Polygon.

Python SDK

The export format of the polygon is similar to the import format.

Learn more about exporting annotations using the SDK here

JSON

You will receive a JSON file when you generate an export from the app.

ParameterAsset typeDescription
schemaIdImage

Tiled imagery
The ID of the schema containing all of the information needed for rendering your annotation.
featureIdImage

Tiled imagery
ID of the annotation.
titleImage

Tiled imagery
Name of the annotation in the ontology.
colorImage

Tiled imagery
Color of the annotation in the ontology.
polygon.xImagex-coordinate for Point annotation. For Tiled imagery, this value is the longitude.
polygon.yImagey-coordinate for Point annotation. For Tiled imagery. this value is the latitude.
instanceURIImageAnnotation information hosted on Labelbox servers.
typeTiled imageryAnnotation type
geometry.coordinatesTiled imageryLongitude and latitude, in that order.

Format

{
    "featureId": "ck9blnafk1d070yf5bhq4q1fv",
    "schemaId": "ck9blmq1lnlxv0889cu4r18mx",
    "title": "Black bird",
    "value": "black_bird",
    "color": "#006FA6",
    "polygon": [
        {
            "x": 3665.814,
            "y": 351.628
        },
        {
            "x": 3762.93,
            "y": 810.419
        },
        {
            "x": 3042.93,
            "y": 914.233
        },
        {
            "x": 2996.047,
            "y": 864
        },
        {
            "x": 3036.233,
            "y": 753.488
        }
    ],
    "instanceURI": "https://api.labelbox.com/masks/feature/ckmuuwhfh00083g68sdwpwa04?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjazUycnZ4MWtxYXpiMDc3MDBtcTI3eDRsIiwib3JnYW5pemF0aW9uSWQiOiJjazUycnZ4MG1wdzRnMDc2NndncXZqdGw5IiwiaWF0IjoxNjE3MDM4NDAwLCJleHAiOjE2MTk2MzA0MDB9.5YaORL6mWpPqgAb6IbWChm4MQo14obOU8LFWbfCEHR0"
}
{
    "featureId": "cknjekt1u00033g68rhvautuz",
    "schemaId": "cknjek2a80jic0y94dn8xgh5a",
    "title": "test2",
    "value": "test2",
    "color": "#FF34FF",
    "type": "polygon",
    "geometry": {
        "coordinates": [
            [
                [
                    -99.2086085262586,
                    19.402699145687013
                ],
                [
                    -99.20676074827523,
                    19.40271185664698
                ],
                [
                    -99.2069136106043,
                    19.40341371560633
                ],
                [
                    -99.20818859228417,
                    19.403328482715512
                ],
                [
                    -99.2086085262586,
                    19.402699145687013
                ]
            ]
        ]
    }
}