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

Problems creating a Skeleton #7

Open
timosmd opened this issue Oct 30, 2020 · 4 comments
Open

Problems creating a Skeleton #7

timosmd opened this issue Oct 30, 2020 · 4 comments

Comments

@timosmd
Copy link

timosmd commented Oct 30, 2020

Hello,

I searched for 2 full days for python modules which support creating a medial axis of a 3 dimensional mesh. Your repository was the only one I found and it looks quite promising. Unfortunately it doesn't seem to work for me as I expect it - although I tried changing the input parameters:

skeletonize_wrong

Also I receive the following error when trying to use the method "edge_collapse" instead of "vertex_clusters": "AttributeError: module 'numpy' has no attribute 'float128'".

Here is the code I used.. What am I doing wrong?

import open3d as o3d
import matplotlib.pyplot as plt
import numpy as np
import skeletor as sk
import trimesh

mesh_name = 'D:/.../Multidirectional_Advanced.stl'
mesh = trimesh.load(mesh_name)

cont = sk.contract(mesh, iter_lim=1000)
swc = sk.skeletonize(cont, method='vertex_clusters', sampling_dist=0.1, output='swc')
swc = sk.clean(swc, mesh)
swc.head()

max_val = max(max(swc.x), max(swc.y), max(swc.z))
fig = plt.figure()
ax = fig.gca(projection='3d')
plt.axis('off')
plt.xlim([-max_val, max_val])
plt.ylim([-max_val, max_val])
ax.set_zlim(-max_val, max_val)
ax.scatter(swc.x, swc.y, swc.z, s=10)
plt.show()

Thanks in advance!

@schlegelp
Copy link
Collaborator

Hi.

Re the float128 error:
What version of Numpy are you running?

Re the skeletonization results:
It's impossible to tell without inspecting your mesh. It would also be helpful if you plotted the swc result as line- not as scatterplot. But here is what you could try:

  1. Inspect the contracted mesh (cont) and make sure that this already looks sort of like a centreline skeleton. If it doesn't I suspect that two things might have happened: (a) the contraction was insufficient and you need to run more iterations or play with the weight parameter WL or (b) there is something strange about your mesh - e.g. to me it looks a bit like the bottom cylinder and the cylinder sticking out sideways aren't actually connected to the rest?
  2. If the contracted mesh looks OK then check what swc looks like before and after sk.clean - maybe the clean-up is causing troubles?

I honestly never tried skeletonizing a mesh like yours and I would not be surprised if the default parameters just don't work for it. If you could share the .stl file, I'd be happy to give it a crack.

Best,
Philipp

@timosmd
Copy link
Author

timosmd commented Oct 30, 2020

Thanks for your quick response!

My Numpy version is 1.18.5 but I just upgraded it to 1.19.3 - problem still consists.

Thanks for the tips, I will have a look at it next week and come back to you with my results!

Attached you can find my .stl I used with the code.

Have a nice weekend!

Multidirectional_Advanced.zip

@schlegelp
Copy link
Collaborator

OK, not sure where the np.float128 issue is coming from (possibly platform dependent?) but I'll drop that bit from the code in the next version.

Re your mesh:
I think the main reason why the results look odd is that your mesh is unevenly sampled - ideally you want each face to be of similar size. I ended up using Blender3d's remesh modifier to fix that. With the remeshed mesh (see attached zip) I was able to get slightly better albeit far from perfect results.

Screenshot 2020-11-02 at 16 55 18

I haven't played around with the parameters much - maybe you can squeeze out a bit more:

import trimesh as tm
import skeleton as sk

m = tm.load('Multidirectional_Advanced_remesh.stl')
fixed = sk.utilities.fix_mesh(m, fix_normals=True)
cont = sk.contract(fixed, SL=10, WH0=1, validate=True, iter_lim=10, operator='umbrella', epsilon=0.05)

Multidirectional_Advanced_remesh.stl.zip

@timosmd
Copy link
Author

timosmd commented Nov 6, 2020

Thanks a lot for trying it - looks a lot better, but still not perfect. Maybe I can reach my goal by adjusting the parameters. Unfortunately I didn't have time to come back to this problem yet. But I will do my best to try it next week or the week after and let you know about my results :)

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