Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: polygon notation from mask #48

Open
chrbrgst opened this issue Nov 5, 2021 · 0 comments
Open

bug: polygon notation from mask #48

chrbrgst opened this issue Nov 5, 2021 · 0 comments

Comments

@chrbrgst
Copy link

chrbrgst commented Nov 5, 2021

the algorithm that is used to create the polygon notation from a mask sometimes creates single-point polygons.
When using pycocotools' annToMask, this throws an exception:

import imantics as imt
import numpy as np
from pycocotools.coco import COCO
import json

mask = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0], [1, 1, 1, 0, 0, 0], [1, 1, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0]]
mask = np.array(mask, dtype='uint8')

dataset = imt.Dataset('dataset')
catt = imt.Category('dummy', id=1)

maskk = imt.Mask(mask)

img = np.reshape(np.array([mask, mask, mask]), [6, 6, 3])
imgg = imt.Image(img, path='hello/world.png')
dataset.add(imgg)

ann = imt.Annotation.from_mask(maskk, image=imgg, category=catt)

dataset.add(ann)
with open('dummy.json', 'w') as f:
f.write(json.dumps(dataset.coco()))
coco = COCO('dummy.json')
new_mask = coco.annToMask(coco.anns[1])

by rejecting those single(or two)-point polygons, this can be solved:
just edit the polygon- method in the Mask-Class and replace:
polygons = [polygon.flatten() for polygon in polygons]
with
polygons = [polygon.flatten() for polygon in polygons if polygon.shape[0] > 2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant