
In the world of computer vision, the performance of your model is only as good as the quality—and volume—of your training data. As the size of semantic segmentation datasets continues to grow, researchers and engineers face an increasingly painful bottleneck: preparing polygon-based COCO JSON annotations from raw segmentation masks.
If these individuals have access to an annotation tool like Deep Block, they might not face significant issues. However, there are instances where they are required to manually convert the color masks displayed on images into JSON format. This process can be particularly challenging and time-consuming, especially when dealing with large datasets or when the available tools are not optimized for such tasks. In such scenarios, the lack of efficient conversion tools can become a major bottleneck, hindering the progress of their projects and potentially delaying the development of their computer vision models.
At Deep Block, we felt that pain too. That’s why we’re releasing a lightweight, high-performance C++ tool for converting raster segmentation masks into COCO-format JSON annotations—optimized for massive-scale processing, minimal dependencies, and blazing speed.
Whether you're training a new AI model, preparing ground truth for evaluation, or uploading datasets to Deep Block’s no-code image analysis platform—this tool will save you hours, if not days.
Why Python Wasn’t Enough
There are existing Python-based tools for this task. They work. But they’re not fast.
When you’re processing 30,000+ masks (Maybe 10,000,000 masks and 500,000 image files for example), even minor inefficiencies can snowball into serious delays. We found:
-
Libraries like
pycococreator
orlabelme2coco
struggled with large datasets. -
Single-threaded processing wasted modern multi-core CPU power.
- In general, Python is SLOW.
-
Conversions could take hours even on high-end machines.
So we asked: Can we do better?
What We Built
We built a C++17-based segmentation mask converter that reads RGB-colored mask images (like those in the SemSeg Outdoor Pano dataset), extracts contours per class using OpenCV, and emits a COCO-format JSON file.
Key Features:
-
🧠 Semantic segmentation support with polygon mask extraction
-
⚡ Multi-threaded image processing using
std::thread
-
📦 Rapid JSON serialization with RapidJSON
-
🐧 Built and tested on Linux with
g++
and OpenCV4
Performance: What Does “Fast” Actually Mean?
In our benchmarks:
-
Processing more than 30,000 masks on a 12-core CPU in a few seconds.
-
Compared to >minutes on Python equivalents
-
CPU usage was fully utilized across all cores
-
Memory usage remained controlled, allowing large jobs on standard machines
Designed for Deep Block, Open to All
Internally, we designed this tool for preparing large-scale annotations to upload into the Deep Block platform, where teams analyze and fine-tune segmentation results using no-code workflows.
But this tool isn’t just for us. We’re releasing it completely open-source under the MIT License—so you can use it, adapt it, or even embed it into your own pipeline.
You’ll find:
-
Clean, well-documented C++ source code
-
Easy compilation instructions
-
Modifiable constants for thread count, resolution, and color-class mapping
How to Use It
Clone the repo and compile:
git clone https://github.com/omnis-labs-company/raster-mask-to-cocojson.git
cd raster-mask-to-cocojson
g++ -std=c++17 -O3 -pthread -o mask_to_coco mask_to_coco.cpp `pkg-config --cflags --libs opencv4`
Then run it with your own dataset.
Full usage instructions and customization options are in the README.
The Bigger Picture
We believe annotation tooling shouldn't be the bottleneck to AI development. With high-res aerial imagery, satellite data, medical scans, or autonomous vehicle datasets, the need for scalable and rapid preprocessing tools has never been greater.
By combining traditional high-performance computing (HPC) principles with modern C++ and open-source libraries, we hope to empower researchers, startups, and enterprises alike to focus on building better models—not battling inefficient pipelines.
Final Thoughts
This project is just one small part of our broader mission at Deep Block: to bring artificial intelligence to everyone, without the engineering overhead.
Happy annotating!
— The Deep Block Team