Comments (4)
OK, first re the export: Trimesh appears to only support dxf, dict and svg as output formats for Path3D. See file_type
in the docstring:
>>> help(trimesh.Path3D.export)
Signature: s.skeleton.export(file_obj=None, file_type=None, **kwargs)
Docstring:
Export the path to a file object or return data.
Parameters
---------------
file_obj : None, str, or file object
File object or string to export to
file_type : None or str
Type of file: dxf, dict, svg
Returns
---------------
exported : bytes or str
Exported as specified type
I work mostly with neurons (see below) and in that world, SWC is the most common format for skeletons. I'm not familiar with the vtk format but I would perhaps look into meshio and check if it's capable of dealing with meshes that have only vertices and edges (but no faces).
Now for the post-processing: although this might change in the future, skeletor
's capabilities in this department are fairly limited. If I was you, I'd use navis (which is what I wrote skeletor
for). navis
is nominally meant for skeletons of neurons but at the end of the day it doesn't matter what the skeleton represents. Here are some quick pointers from your example #27:
import navis
# Create a neuron from your skeleton
n = navis.TreeNeuron(skel, soma=None)
# Example 1: Remove all twigs under a certain size (adjust `size` parameter!)
no_twigs = navis.prune_twigs(n, size=100)
# Example 2: keep only the longest linear section in your skeleton
long1 = navis.longest_neurite(n, from_root=False)
# Example 3: keep only the two longest linear section sin your skeleton
long2 = navis.longest_neurite(n, n=2, from_root=False)
# Turn any of the above back into a skeletor.Skeleton
# (note that processing might have broken the mesh vertices <-> skeleton nodes mapping
skel2 = sk.Skeleton(no_twigs.nodes[['node_id', 'parent_id', 'x', 'y', 'z', 'radius']])
from skeletor.
OK, first re the export: Trimesh appears to only support dxf, dict and svg as output formats for Path3D. See
file_type
in the docstring:>>> help(trimesh.Path3D.export) Signature: s.skeleton.export(file_obj=None, file_type=None, **kwargs) Docstring: Export the path to a file object or return data. Parameters --------------- file_obj : None, str, or file object File object or string to export to file_type : None or str Type of file: dxf, dict, svg Returns --------------- exported : bytes or str Exported as specified typeI work mostly with neurons (see below) and in that world, SWC is the most common format for skeletons. I'm not familiar with the vtk format but I would perhaps look into meshio and check if it's capable of dealing with meshes that have only vertices and edges (but no faces).
Now for the post-processing: although this might change in the future,
skeletor
's capabilities in this department are fairly limited. If I was you, I'd use navis (which is what I wroteskeletor
for).navis
is nominally meant for skeletons of neurons but at the end of the day it doesn't matter what the skeleton represents. Here are some quick pointers from your example #27:import navis # Create a neuron from your skeleton n = navis.TreeNeuron(skel, soma=None) # Example 1: Remove all twigs under a certain size (adjust `size` parameter!) no_twigs = navis.prune_twigs(n, size=100) # Example 2: keep only the longest linear section in your skeleton long1 = navis.longest_neurite(n, from_root=False) # Example 3: keep only the two longest linear section sin your skeleton long2 = navis.longest_neurite(n, n=2, from_root=False) # Turn any of the above back into a skeletor.Skeleton # (note that processing might have broken the mesh vertices <-> skeleton nodes mapping skel2 = sk.Skeleton(no_twigs.nodes[['node_id', 'parent_id', 'x', 'y', 'z', 'radius']])
@schlegelp I tried to convert long1 to the Skeleton object and show the pruning result. However, it said that the index out of the bounds. Do you know the reasons?
from skeletor.
Ah, I had forgotten that skeletor
expects sequentially numbered node IDs while navis
doesn't care much about that. During pruning we dropped a bunch of nodes and navis
doesn't renumber them.
We have to add an intermediate step at which we convert the more forgiving navis
node table into a SWC table that skeletor is happy with;
# This renumbers nodes
swc = navis.io.swc_io.make_swc_table(long1)
# We also need to rename some columns
swc = swc.rename({'PointNo': 'node_id', 'Parent': 'parent_id', 'X': 'x', 'Y': 'y', 'Z': 'z', 'Radius': 'radius'}, axis=1).drop('Label', axis=1)
# Skeletor excepts node IDs to start with 0, but navis starts at 1 for SWC
swc['node_id'] -= 1
swc.loc[swc.parent_id > 0, 'parent_id'] -= 1
# Create the skeletor.Skeleton
skel2 = sk.Skeleton(swc)
For what it's worth: navis has an independent built-in plotting system too. So if all you're after is visualization, you don't need to go back to skeletor.
# Plot only the skeleton
navis.plot3d(long1)
# From terminal only: to clear the 3d plot
navis.clear3d()
# From terminal only: to close the 3d plot
navis.close3d()
# Plot skeleton with mesh
navis.plot3d([long1, skel.mesh])
from skeletor.
Ah, I had forgotten that
skeletor
expects sequentially numbered node IDs whilenavis
doesn't care much about that. During pruning we dropped a bunch of nodes andnavis
doesn't renumber them.We have to add an intermediate step at which we convert the more forgiving
navis
node table into a SWC table that skeletor is happy with;# This renumbers nodes swc = navis.io.swc_io.make_swc_table(long1) # We also need to rename some columns swc = swc.rename({'PointNo': 'node_id', 'Parent': 'parent_id', 'X': 'x', 'Y': 'y', 'Z': 'z', 'Radius': 'radius'}, axis=1).drop('Label', axis=1) # Skeletor excepts node IDs to start with 0, but navis starts at 1 for SWC swc['node_id'] -= 1 swc.loc[swc.parent_id > 0, 'parent_id'] -= 1 # Create the skeletor.Skeleton skel2 = sk.Skeleton(swc)For what it's worth: navis has an independent built-in plotting system too. So if all you're after is visualization, you don't need to go back to skeletor.
# Plot only the skeleton navis.plot3d(long1) # From terminal only: to clear the 3d plot navis.clear3d() # From terminal only: to close the 3d plot navis.close3d() # Plot skeleton with mesh navis.plot3d([long1, skel.mesh])
Thanks for your help. The following part for me is to compute the closest distance between pruning skeleton and original mesh so that I can construct a new mapping from new skeleton to original mesh, since you mentioned before that mapping from skeleton to mesh will be affected by using navis
from skeletor.
Related Issues (20)
- Cannot show the skeleton path HOT 21
- Extracting extremities in a skeleton HOT 10
- Use wavefront to contract meshes?
- Loading a custom mesh and skeletonizing it? HOT 2
- TypeError: 'path' is an invalid keyword argument for this function HOT 3
- How can I change the swc output after skeletonize.by_teasar HOT 3
- Set node sparsification distance HOT 2
- How do I run the code? HOT 1
- How to save the skeleton without the mesh? HOT 7
- About citations of the wave fronts method HOT 2
- How to get simpler skeleton on the skeletonize result? HOT 1
- Issue when computing skeleton (with non-watertight mesh) HOT 6
- Remove excess and fragmented shoots from the skeleton HOT 3
- Plotting issues HOT 7
- inv_dist value for .by_teasar() HOT 1
- AttributeError: module 'skeletor' has no attribute 'example_mesh' HOT 9
- .by_tangent_ball() doesnt return any result
- Vascular structure with different radii HOT 15
- Literature sources for vertex clustering? HOT 2
- Modify the leafs or roots HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from skeletor.