chrise96 / image-to-coco-json-converter

Convert segmentation RGB mask images to COCO JSON format
199 stars 57 forks source link

Background annotations #13

Closed Testbild closed 2 years ago

Testbild commented 2 years ago

Hello,

I have a question about background annotations:

I have a Black and White mask: Black == Background ; White == The object I segmented

Unfortunately now, when I only add the white part to the category the script complains, that it has a key error at (0,0,0). But if I add the (0,0,0) I have the issue, that the background also is an annotation.

Do you have any idea how to resolve this?

Hnd7 commented 2 years ago

I was also facing the same problem. It was solved by adding this line "if color != '(0, 0, 0)': " into the second for loop.

.
.
.
  for color, sub_mask in sub_masks.items():
            if color != '(0, 0, 0)':  
                category_id = category_colors[color] 
.
.
.
Testbild commented 2 years ago

I was just going to post this as I figured this out as well. Can confirm this works. Thanks for the quick reply!

Edit: One more thing, the color is a string and not a tuple, as I first thought. Maybe that saves someone some time.