def _floodfill(self, img):
back = Back._scharr(img)
# Binary thresholding.
back = back > 0.05
# Thin all edges to be 1-pixel wide.
back = skm.skeletonize(back)
# Edges are not detected on the borders, make artificial ones.
back[0, :] = back[-1, :] = True
back[:, 0] = back[:, -1] = True
# Label adjacent pixels of the same color.
labels = label(back, background=-1, connectivity=1)
# Count as background all pixels labeled like one of the corners.
corners = [(1, 1), (-2, 1), (1, -2), (-2, -2)]
for l in (labels[i, j] for i, j in corners):
back[labels == l] = True
# Remove remaining inner edges.
return skm.opening(back)
评论列表
文章目录