python - Filling holes in objects that touch the border of an image -


i'm trying fill holes in below image.

image filled

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

enter image description here

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() 

enter image description here


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -