python - Filling holes in objects that touch the border of an image -
i'm trying fill holes in below image.

when use scipy's binary_fill_holes(), successful, exception of objects touch image's border.

are there existing python functions can fill holes in objects touch border? tried adding white border around image, resulted in entire image being filled.
this assumes there more background other stuff. connected component analysis on image. extract largest component (assumed background), , sets else white.
import numpy np import matplotlib.pyplot plt import skimage.morphology, skimage.data img = skimage.data.imread('j1esv.png', 1) labels = skimage.morphology.label(img) labelcount = np.bincount(labels.ravel()) background = np.argmax(labelcount) img[labels != background] = 255 plt.imshow(img, cmap=plt.cm.gray) plt.show() 
Comments
Post a Comment