Binary and PNG segmentation masks

Segmentation as images: pixel values say which class or which object a pixel belongs to, and a JSON file maps the values to class names.

Data
Images
Labels
Masks
Files
.png, .json
Import / export
Yes / Yes
The format

What is the PNG masks format?

Masks are the simplest way to store segmentation: an image of the same size as the photo, where pixel values say which class (a semantic mask) or which object (an instance mask) each pixel belongs to. There is no single standard, so a set of masks needs a map from pixel values or colors to class names.

Supervisely reads and writes that map as obj_class_to_machine_color.json. Semantic masks go to masks_machine with the same name as the image; instance masks go to masks_instances/<image name>/, one black-and-white file per object, named after its class.

Files

Folder structure and an example

Folder structure for import
dataset
├── obj_class_to_machine_color.json
├── img
│   ├── image_1.jpg
│   └── image_2.jpg
├── masks_instances
│   ├── image_1
│   │   ├── dog_1.png      # one dog
│   │   └── dog_2.png
│   └── image_2
│       └── dog_1.png
└── masks_machine
    ├── image_1.png        # every pixel > 0 is a class value
    └── image_2.png
obj_class_to_machine_color.json (grayscale values)
{
  "Lemon": 170,
  "Kiwi": 85
}
obj_class_to_machine_color.json (RGB colors)
{
  "dog": [50, 50, 50],
  "cat": [100, 100, 100]
}
In and out

Import and export PNG masks in Supervisely

Import PNG masks into Supervisely

  • Import data (Auto Import)

    Drop images, masks and obj_class_to_machine_color.json into a project; semantic and instance masks are both read.

  • Import images with masks

    Imports one or several projects of images with semantic and instance masks; reads the archives of Export as masks.

Export from Supervisely to PNG masks

  • Export as masks

    Exports the images with their Supervisely JSON and any of: color masks by class, machine masks by class index, a black-and-white mask per object, and RGB semantic masks. Large archives are split into parts.

All apps are in the Ecosystem, under Import and Export. Every project is stored in Supervisely JSON in between.

Conversion

Converting PNG masks to and from Supervisely JSON

PNG masksSupervisely JSONNotes
pixels of one value in masks_machineone bitmap of the mapped classPixels with the value 170 become one bitmap of the class mapped to 170.
a file in masks_instances/<image>/one bitmap objectThe class is the file name: dog_1.png → dog.
masks_humanevery object, in its class colorOn export, a semantic mask a person can read.
masks_machine and the JSON mapevery object, as its class index(0, 0, 0) is background, (1, 1, 1) class 1, and so on.
masks_instancesevery object, white on blackOne file per object.