Java教程

【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')

 

 

这篇关于【713】骨架图矢量化实现的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!