marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

Is there a way to get a volumetric image from mesh. #628

Closed antonfrancois closed 2 years ago

antonfrancois commented 2 years ago

Hello,

I am trying to get a volumetric image from a mesh. Exactly the reverse application of the Numpy2volume example. I want to make a mesh in Blender and generate a volumetric image from it, (a bit like a MRI). I figured that is is possible to 'hack' vedo to so, as a vtk vrapper.

For now I managed to make it look like a volumetric image using the following code. However is there an easy way to get a 3D numpy array ?

surf = vedo.Mesh('ifile.stl').normalize().wireframe()
vol = vedo.mesh2Volume(surf, spacing=(0.02, 0.02, 0.02)).alpha([0,0.5]).c('blue')
plt = SlicerPlotter(vol,
                      bg='white', bg2='lightblue',
                      cmaps=("gist_ncar_r","jet","Spectral_r","hot_r","bone_r"),
                      useSlider3D=False,
)
vedo.interactive()
plt.show().close()

Thank you !

marcomusy commented 2 years ago

Hi not sure if I understand what you're trying to achieve.. what is the data content of the voxel? just a mask? If so you can look at binarize() : https://github.com/marcomusy/vedo/blob/7c7f2adc2e7fee4c881c9bfff3a3c9e709010dd0/examples/volumetric/mesh2volume.py

Exactly the reverse application of the Numpy2volume example.

that's simply vol.tonumpy()

antonfrancois commented 2 years ago

Thank you, I was looking for the 'tonumpy()' answer. I find you library really well made, and it turned very useful for me to use in my PhD, project. However I find it a bit difficult to find some simple answers like that, leading me to ask dumb question. I went reading the code of the Volume class, parsed the autodoc, looked at some example from your website and didn't found the answer. (Now that I know that the method is called tonumpy() I quickly found that it is located in the BaseVolume class.)

I guess it comes from the fact that there is not active activity on Stackoverflow yet. Anyway, thank you again for your quick answer, I hope that my questions will help future users. Anton

marcomusy commented 2 years ago

Thanks Anton for reporting and for the useful feedback on the documentation. No dumb question! The vedo library now exposes a quite large number of functionalities and it's not trivial to find the one that matters for a user specific case... so feel free to ask if you have any doubts.