facebookresearch / facebookresearch/detectron2
handle annotations with inner holes
- Dominant language
- Python
- Stars
- 34.7k
- Forks
- 7.9k
- PR merge metrics
- No merged PRs in 30d
Description
## 🚀 Feature
I think you need to modify the way polygons are converted into bitmasks, I suppose the function responsible of this conversion is `polygons_to_bitmask` in `detectron2/structures/masks.py`
because it doesn't take into account inner holes of an object
## Motivation & Examples
for example this is the original mask

after turning this object into polygons and feeding it through that function,
this is the reconstructed mask

the solution I have found (up to you to decide if it's good) is to delete the
```
line 35 rle = mask_util.merge(rles)
```
and replace it with
```
if len(rles) >2:
reduced=np.add.reduce(mask_util.decode(rles),axis=2)
rle = np.where(reduced>=2,0,reduced).astype(np.bool)
else:
rle = mask_util.merge(rles)
rle = mask_util.decode(rle).astype(np.bool)
return rle
```
my idea is we check if there is multiple masks, add the masks into one mask, overlays between masks will be expressed as value greater than 2, so we set these values to zero
Contributor guide
Assessment
This issue has not been assessed yet.