[Feature] convert mask image into json #1101
Replies: 7 comments
-
Hello, I have been wondering the same thing. |
Beta Was this translation helpful? Give feedback.
-
Maybe this code can give you some idea import contextlib IMAGE_NAME = 'path/to/your/mask/' @contextlib.contextmanager all_point = []
out_dict = {'version':"4.5.6", with open(JSON_NAME, "w") as f: |
Beta Was this translation helpful? Give feedback.
-
Using opencv findContours seems a simple way, but it leads to dense points issue (eg. a 800*800 image, will generate 3000 points and hard to drag or move them in qt). |
Beta Was this translation helpful? Give feedback.
-
Hi, I was wondering this question as well and found quite a simple solution on stack overflow with a help of a library called imantics.
This way you get a polygon array with the same formatting as in the labelme files, for the same format as in COCO like datasets you can use polygons.segmentation instead. Edit: Oh, maybe I should add, that I used the detectron2's segmentation model (R50 FPN Mask R-CNN) to get ou the prediction and the mask, so that part of the code may differ for other codes, but the output I get is boolean tensor array (thus I convert it to numpy() and multiply by one) that gets me array of 0s and 1s which has following proportions [# of predicted segmentation' masks, width, height] |
Beta Was this translation helpful? Give feedback.
-
what if i want to include the image data? import base64 ` |
Beta Was this translation helpful? Give feedback.
-
@randomrushgirl I think I had a similar issue as you do at first... if I remember correctly I think I ended up going through my new generated json file trying to figure out the issue by comparing it to a working one to figure out what might be wrong... If you think the generated img_data is the problem, what I think should work is generating it, copying it into some working json file (replace the original image data with your new one) and if you see your original labels on a new img background in labelme, then you know the base64 is not the issue, but the json formatting is ( I think that was my case and it was something really stupid like ' ' instead of " " which made it not work) However I generate the data like this and it works alright:
I pass the img_data into my outer dict which looks like this:
|
Beta Was this translation helpful? Give feedback.
-
@KristynaPijackova you're right on the money, the image is different but the labelled annotations is as expected. I generate my data and pass it into an outer dictionary in a similar way you do so I checked my code after I saw your reply and the issue seemed to lie with how I was passing my image data to the JSON file. Thanks for the help! 😄 |
Beta Was this translation helpful? Give feedback.
-
Hello, I was wondering if it possible to convert an annotated image generated by my network into labelme's json file format, given the original image and the mask image available? I think it may be possible, but I don't know how to code it.
Beta Was this translation helpful? Give feedback.
All reactions