For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  1. Create a Multipolygon from several Polygon objects.

  2. Add a Multipolygon class to project meta.

  3. Upload an image annotation with a Multipolygon label.

  4. Download and deserialize the annotation.

  5. Draw the label locally.

  6. Convert a Multipolygon label into separate Polygon labels.

Supervisely Python SDK version 6.74.10 or newer is required.

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