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
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.
Folder structure and an example
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{
"Lemon": 170,
"Kiwi": 85
}{
"dog": [50, 50, 50],
"cat": [100, 100, 100]
}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.jsoninto 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.
Converting PNG masks to and from Supervisely JSON
| PNG masks | Supervisely JSON | Notes |
|---|---|---|
pixels of one value in masks_machine | one bitmap of the mapped class | Pixels with the value 170 become one bitmap of the class mapped to 170. |
a file in masks_instances/<image>/ | one bitmap object | The class is the file name: dog_1.png → dog. |
masks_human | every object, in its class color | On export, a semantic mask a person can read. |
masks_machine and the JSON map | every object, as its class index | (0, 0, 0) is background, (1, 1, 1) class 1, and so on. |
masks_instances | every object, white on black | One file per object. |