Converting Polygon bounded boxes in the Dataturks JSON format to mask images
This blog is about converting the Dataturks JSON format for polygon bounded box annotations to png encoded binary mask images, which are often necessary as input to create training data for teaching image segmentation models such as mask RCNN, etc. The code provided also scrapes the original images from the link provided in the file as the content value.
A typical training sample in the JSON would look like the following :
In the given format, the content refers to the link containing the original image present in the dataset annotated. The annotations consist of the label along with the points marking the bounding polygon around the region of interest, apart from the dimenions of the images.
Here’s a code to convert any given Dataturks polygon bounding box annotation file to a dataset containing the groundtruth images along with the mask images :
A couple of dependencies:
pip install scikit-image
pip install numpy
The usage of the above code for the necessary conversion is as follows :
python Dataturks_to_mask_images.py <path to Dataturks JSON format> <path to folder to store the downloaded groundtruth images> <path to folder to store mask images>
If the annotation contains multiple classes or objects for a particular image, the mask is created such that each mask image contains only one object of one class, a format suited for conversion to the MS-COCO Data format easily.
A sample mask created is given below :
If you have any queries or suggestions, I would love to hear about it. Please write to me at email@example.com.
Shameless plugin: We are a data annotation platform to make it super easy for you to build ML datasets. Just upload data, invite your team and build datasets super quick. Check us out!