jsbroks / imantics

:camera: Reactive python package for managing, creating and visualizing different deep-learning image annotation formats
https://imantics.rtfd.io
MIT License
364 stars 68 forks source link

Is it possible that imantics is missing the mask outermost pixels? #43

Open bpmsilva opened 3 years ago

bpmsilva commented 3 years ago

Hello everyone,

I'm converting binary masks created from exported COCO Annotator JSON files. From a JSON file, I generate binary masks using cv2.fillPoly and process them. This results in more masks that are usually next to each other (their pixels touch each other). However, after I generate the annotation segmention (using [list(map(round, polygon)) for polygon in mask.polygons()]) and importing the generated JSON to COCO Annotator, I see that these masks do not touch each other. There is a thin space between them. That's why I wonder if in the imantics conversion some pixels are missed. Another possibility is a bug or a different convention in cv2.fillPoly. I'll investigate the problem, but any help here is welcome.

I really appreciate any help you can provide.

Thormidable commented 2 years ago

I think the polygon finds min and max, rather than min and stop. this means that the 'topmost' pixels aren't inside the polygon, when they are interpreted as the latter format.

a two by two box of pixels (pixels [1,1],[2,1],[2,2],[1,2] labelled as ones) produces the polygon points [1,1],[2,1],[2,2],[1,2] which is interpreted as most systems as a 1 by 1 box

I think returning [1,1],[3,1],[3,3],[1,3] would give the results you expect.

ZhouBay-TF commented 2 years ago

6 `polygons_list = (Mask(mask).polygons()).points for points in polygons_list:

print(points)

    for point in points:
        cv2.circle(jpg, (point[0], point[1]), 5, (255, 0, 0), -1)
cv2.imwrite("6.jpg", jpg)`

Some position coordinates are missing thank you.