Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get simpler skeleton on the skeletonize result? #38

Open
xiruiYan opened this issue Mar 31, 2023 · 1 comment
Open

How to get simpler skeleton on the skeletonize result? #38

xiruiYan opened this issue Mar 31, 2023 · 1 comment

Comments

@xiruiYan
Copy link

Hi, thanks for your work!
I am a new at this , and I am trying to get the skeleton for animation from a mesh. I've run this code and get result like the left one in this picture, which have much more joints than I need. How can I get the right result in this picture?

image

Can you give some advice on this? thank you very much!

@schlegelp
Copy link
Collaborator

Simplifying or downsampling the skeleton is not terribly difficult but there is currently no convenience method built directly into skeletor. I will have a think about whether to add one.

For now, you could use navis:

pip3 install navis

Then:

# Run the example skeletonization

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

# Turn the skeletor object into navis 

>>> import navis 
>>> n = navis.TreeNeuron(skel, soma=None)
>>> n.n_nodes  # Number of nodes/vertices
1103

# Option 1: downsample by given factor
# Note that his will never remove branch or end points which means 
# there is a limit to how much you can downsample

>>> ds = navis.downsample_neuron(n, downsampling_factor=10)
>>> ds.n_nodes  # Check that we now have fewer nodes/vertices
500

# Option 2: resample to given segment length
# This also works to "upsample" the skeleton

>>> res = navis.resample_skeleton(n, resample_to=1000)
>>> res.n_nodes  # Check that we now have fewer nodes/vertices
517

# Turn navis object to skeletor Skeleton

>> skel2 = sk.Skeleton(ds.nodes[['node_id', 'parent_id', 'x', 'y', 'z', 'radius']].copy())

A potential catch here is that by downsampling you break the correspondence between the vertices in your original mesh and the nodes in the skeleton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants