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

Exporting skeletons as object files #243

Open
conochur opened this issue Apr 3, 2024 · 3 comments
Open

Exporting skeletons as object files #243

conochur opened this issue Apr 3, 2024 · 3 comments

Comments

@conochur
Copy link

conochur commented Apr 3, 2024

I know that there's a feature in the GUI to export skeleton selections as .obj files, but can one do the same using PyMaid?

@schlegelp
Copy link
Collaborator

schlegelp commented Apr 3, 2024

Yes, in theory! In practice it depends a bit on what exactly it is you are after.

The obj format is (to my knowledge) most commonly used for meshes, i.e. an object with faces and vertices. It's pretty straight forward to convert a skeleton into a tubular mesh. OBJ appears to also support curve/line objects though. Not sure which of the two option CATMAID is exporting?

@conochur
Copy link
Author

conochur commented Apr 3, 2024

Thanks for the response! I'm looking for a mesh file that I can pop into other rendering software. But would like to do it programmatically. Do you have any recommendations for accomplishing that from python using the coordinate and radius data?

@schlegelp
Copy link
Collaborator

schlegelp commented Apr 4, 2024

That functionality fortunately already exists. Here's a minimal example:

>>> import pymaid
>>> import navis

>>> # Grab your CATMAID skeleton
>>> s = pymaid.get_neuron()
>>> type(s)
pymaid.core.CatmaidNeuron

>>> # Turn the skeleton into a tubular mesh
>>> # You can tune the resolution using `tube_points` parameter
>>> m = navis.conversion.tree2meshneuron(s)
>>> type(m)
navis.core.mesh.MeshNeuron

>>> # Save as OBJ
>>> _ = m.trimesh.export('skeleton_mesh.obj')

Screenshot 2024-04-04 at 10 15 40
Original skeleton in yellow; mesh generated from skeleton in blue.

A couple notes:

  1. These meshes can get fairly large. You could consider e.g. downsampling the neuron before or after turning it into a mesh.
  2. The mesh will look funny if any of the node radii are missing or <=0 and the function will give a warning if that's the case. You can clip radii at a minimum radius like so:
    >>> s.nodes.loc[s.nodes.radius.fillna(0) <= 0), 'radius'] = 100

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