其他分享
首页 > 其他分享> > 【713】骨架图矢量化实现

【713】骨架图矢量化实现

作者:互联网

参考:骨架矢量化sknw源码研读

代码:

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