用于从 3D 网格中提取骨架的 Python 3 库
项目描述
骨架
与其同名的不同,这个 Python 3 库并没有(还)试图征服 Eternia,而是将网格变成骨架。
提醒:skeletor1.0.0
介绍了一些重大变化和重大重组。
有关详细信息,请参阅更改日志
。
安装
pip3 install skeletor
对于开发版:
pip3 install git+https://github.com/navis-org/skeletor@master
依赖项
自动安装pip
:
networkx
numpy
pandas
scipy
scikit-learn
trimesh
tqdm
python-igraph
ncollpyde
可选,因为对核心功能不是严格要求,但强烈推荐:
- trimesh 需要pyglet来预览 3D 网格/骨架:
pip3 install pyglet
- fastremap使用一些方法实现相当大的加速:
pip3 install fastremap
文档
有关详细信息,请参阅文档。
可以在此处找到更改日志。
快速开始
对于不耐烦的人来说,一个简单的例子:
>>> import skeletor as sk
>>> mesh = sk.example_mesh()
>>> fixed = sk.pre.fix_mesh(mesh, remove_disconnected=5, inplace=False)
>>> skel = sk.skeletonize.by_wavefront(fixed, waves=1, step_size=1)
>>> skel
<Skeleton(vertices=(1258, 3), edges=(1194, 2), method=wavefront)>
所有骨架化方法都返回一个Skeleton
对象。这些只是表示和检查结果的方便对象。
>>> # location of vertices (nodes)
>>> skel.vertices
array([[16744, 36720, 26407],
...,
[22076, 23217, 24472]])
>>> # child -> parent edges
>>> skel.edges
array([[ 64, 31],
...,
[1257, 1252]])
>>> # Mapping for mesh to skeleton vertex indices
>>> skel.mesh_map
array([ 157, 158, 1062, ..., 525, 474, 547])
>>> # SWC table
>>> skel.swc.head()
node_id parent_id x y z radius
0 0 -1 16744.005859 36720.058594 26407.902344 0.000000
1 1 -1 5602.751953 22266.756510 15799.991211 7.542587
2 2 -1 16442.666667 14999.978516 10887.916016 5.333333
>>> # Save SWC file
>>> skel.save_swc('skeleton.swc')
如果您安装了pyglet
(见上文),您还可以使用trimesh
的绘图功能来检查结果:
>>> skel.show(mesh=True)
基准
基准测试fastremap
在安装了可选依赖
项的 2018 MacBook Pro(2.2 GHz Core i7,32Gb 内存)上
运行。请注意,其中一些功能(例如收缩和 TEASAR/顶点集群骨架化)可能会根据参数化在速度上发生很大变化。
贡献
拉请求总是受欢迎的!
参考文献和致谢
网格收缩和边缘折叠方法基于这篇论文:
[1] Au OK, Tai CL, Chu HK, Cohen-Or D, Lee TY. Skeleton extraction by mesh contraction. ACM Transactions on Graphics (TOG). 2008 Aug 1;27(3):44.
摘要和论文可以在这里找到。另请参阅此YouTube 视频。
骨架中的一些代码是从 由#0K Srinivasan Ramachandran 创建并在 GPL3 下发布的 Blender 3D的Py_BL_MeshSkeletonization插件修改的。
网格 TEASAR 方法改编自 Sven Dorkenwald、Casey Schneider-Mizell 和 Forrest Collman在meshparty中的实现。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。