def skel_to_graph(skel):
"""
Transform skeleton into its branches and nodes, by counting the number
of neighbors of each pixel in the skeleton
"""
convolve_skel = 3**skel.ndim * ndimage.uniform_filter(skel.astype(np.float)) # 3x3 square mean
neighbors = np.copy(skel.astype(np.uint8))
skel = skel.astype(np.bool)
neighbors[skel] = convolve_skel[skel] - 1
edges = morphology.label(np.logical_or(neighbors == 2, neighbors ==1),
background=0)
nodes = morphology.label(np.logical_and(np.not_equal(neighbors, 2),
neighbors > 0), background=0)
length_edges = np.bincount(edges.ravel())
return nodes, edges, length_edges
评论列表
文章目录