Multipolygons
How to create, upload, download, draw, and split Multipolygon labels in Python SDK
Introduction
In this tutorial, you will learn how to work with sly.Multipolygon in Supervisely Python SDK. Multipolygon is useful when one label must contain several separate polygon parts, for example one building group, one road island object, or one instance split into disconnected visible regions.
You will learn how to:
Create a
Multipolygonfrom severalPolygonobjects.Add a Multipolygon class to project meta.
Upload an image annotation with a Multipolygon label.
Download and deserialize the annotation.
Draw the label locally.
Convert a Multipolygon label into separate Polygon labels.
Prepare credentials
Prepare ~/supervisely.env with credentials and load it before creating the API client.
import os
from dotenv import load_dotenv
import supervisely as sly
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api.from_env()Create a project and class
Create a Multipolygon
A Multipolygon is created from two or more polygon parts. Each part can have its own holes.
Upload image and annotation
Download and deserialize annotation
Draw Multipolygon locally
Convert Multipolygon to polygons
Use Label.convert() when you need one Polygon label per Multipolygon part.
You can also get polygon geometries directly:
JSON structure
In Supervisely annotation JSON, Multipolygon uses geometryType: "multipolygon" and stores parts in the parts field.
Recap
In this tutorial, you created a Multipolygon class, uploaded and downloaded a Multipolygon label, rendered it locally, and converted it into separate Polygon labels.
Last updated