facebookresearch / facebookresearch/detectron2

handle annotations with inner holes

Open
#4,196 6 comments 2 reactions 0 assignees View on GitHub
enhancement
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
![image](https://user-images.githubusercontent.com/49212088/162347594-4b6123c6-b0b6-4048-a87c-7d9378c9e367.png)

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

![image](https://user-images.githubusercontent.com/49212088/162348341-797cbfec-8abb-4180-bfcd-4f6468a88329.png)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.