https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/291371
it is better to pretrain with clean mask + augmentation.
from skimage import measure
def fill_hole(m):
filled = m.copy()
pad = np.pad(m, 4)
lb = measure.label(pad < 0.5, background=0, connectivity=1)
u, cc = np.unique(lb, return_counts=True)
if len(u) > 2:
#print(u, cc)
lb = lb[4:-4, 4:-4]
for uu in u[2:]:
filled[lb == uu] = 1
return filled
how to use?
1. decode instance from the csv file. e.g. call this m
2. fill the hole: m= fill_hole(m)
3. read the red channel,e.g. r
4. recovered clean instance mask = r & m (bitwise and operation)