skeletor
skeletor copied to clipboard
Problems creating a Skeleton
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:
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!
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:
- 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 parameterWLor (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? - If the contracted mesh looks OK then check what
swclooks like before and aftersk.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
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!
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.
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)
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 :)