【713】骨架图矢量化实现
作者:互联网
代码:
from skimage.morphology import skeletonize from skimage import data import sknw import numpy as np import matplotlib.pyplot as plt # 骨架提取 img = data.horse() ske = skeletonize(~img).astype(np.uint16) # 矢量化调用函数 graph = sknw.build_sknw(ske) # draw image plt.imshow(img, cmap='gray') # draw edges by pts for (s, e) in graph.edges(): ps = graph[s][e]['pts'] plt.plot(ps[:, 1], ps[:, 0], 'green') # draw node by o node, nodes = graph._node, graph.nodes() ps = np.array([node[i]['o'] for i in nodes]) plt.plot(ps[:, 1], ps[:, 0], 'r.') # title and show plt.title('Build Graph') plt.show() # plt.savefig('pc.png')
标签:node,ps,plt,713,骨架,矢量化,graph,import,sknw 来源: https://www.cnblogs.com/alex-bn-lee/p/16324900.html