Skip to main content

Python 3 library to extract skeletons from 3D meshes

Project description

Generic badge Tests DOI

Skeletor

Unlike its namesake, this Python 3 library does not (yet) seek to conquer Eternia but to turn meshes into skeletons.

Heads-up: skeletor 1.0.0 introduced some breaking changes and major reorganizations. Please see the changelog for details.

Install

pip3 install skeletor

For the dev version:

pip3 install git+https://github.com/navis-org/skeletor@master

Dependencies

Automatically installed with pip:

  • networkx
  • numpy
  • pandas
  • scipy
  • scikit-learn
  • trimesh
  • tqdm
  • python-igraph
  • ncollpyde

Optional because not strictly required for the core functions but highly recommended:

  • pyglet is required by trimesh to preview meshes/skeletons in 3D: pip3 install pyglet
  • fastremap for sizeable speed-ups with some methods: pip3 install fastremap

Documentation

Please see the documentation for details.

The changelog can be found here.

Quickstart

For the impatient a quick example:

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

All skeletonization methods return a Skeleton object. These are just convenient objects to represent and inspect the results.

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

If you installed pyglet (see above) you can also use trimesh's plotting capabilities to inspect the results:

>>> skel.show(mesh=True)

skeletor_example

Benchmarks

skeletor_examples

Benchmarks were run on a 2018 MacBook Pro (2.2 GHz Core i7, 32Gb memory) with optional fastremap dependency installed. Note some of these functions (e.g. contraction and TEASAR/vertex cluster skeletonization) can vary a lot in speed based on parameterization.

Contributing

Pull requests are always welcome!

References & Acknowledgments

Mesh contraction and the edge collapse approach are based on this paper: [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. The abstract and the paper can be found here. Also see this YouTube video.

Some of the code in skeletor was modified from the Py_BL_MeshSkeletonization addon for Blender 3D created by #0K Srinivasan Ramachandran and published under GPL3.

The mesh TEASAR approach was adapted from the implementation in meshparty by Sven Dorkenwald, Casey Schneider-Mizell and Forrest Collman.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skeletor-1.2.0.tar.gz (189.9 kB view details)

Uploaded Source

Built Distribution

skeletor-1.2.0-py3-none-any.whl (206.1 kB view details)

Uploaded Python 3

File details

Details for the file skeletor-1.2.0.tar.gz.

File metadata

  • Download URL: skeletor-1.2.0.tar.gz
  • Upload date:
  • Size: 189.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for skeletor-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e878aef54a365510371e4a3b7b030268f3d29d8f4d0156158aca0174dba20bda
MD5 547c49f43009b90d57d1afd4c0de2f7d
BLAKE2b-256 15ea022dee65c27ed57b030818d1fa70a4eea5fd7b12775aec2823d81cb5f804

See more details on using hashes here.

File details

Details for the file skeletor-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: skeletor-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 206.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for skeletor-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb9ea1880f8661fc67d419855db3e49c22c1c85a1dc3f5875be843cdcda09f4d
MD5 f3e68877d16bd1a81b1f8a6447330dcd
BLAKE2b-256 354e02bb3550a22ae327c335ce8535e6859eeddeb3a32f1964eea5d28c0f4ec8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page