Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render segmentation, stored in a NumPy array, with VTK

Tags:

vtk

itk

I have a segmentation, in a 3D numpy.ndarray, which I would like to render into VTK. [See here similar process here: https://pyscience.wordpress.com/2014/11/16/volume-rendering-with-python-and-vtk/ by@somada141]

My current (ad-hoc) solution includes: (1) Save the NumPy array to a Nifiti file with nib. Nifti1Image (2) Load the Nifiti file into vtk with (vtkNIFTIImageReader()) (3) Render the surface with vtkDiscreteMarchingCubes()

My question: How can I convert this 3D NumPy array directly into VTK without the intermediate file.

like image 734
Dov Avatar asked May 18 '26 10:05

Dov


1 Answers

You can use the module numpy_support( https://github.com/Kitware/VTK/blob/master/Wrapping/Python/vtk/util/numpy_support.py) or the new vtk datasetadapter http://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.vtk.numpy_interface.dataset_adapter.html , http://kitware.com/blog/home/post/709

For an example of the first solution see https://pyscience.wordpress.com/2014/09/06/numpy-to-vtk-converting-your-numpy-arrays-to-vtk-arrays-and-files/

Actually while I was looking for an example I found also http://www.vtk.org/Wiki/VTK/Examples/Python/vtkWithNumpy, which I never tried before!

like image 64
lib Avatar answered May 22 '26 02:05

lib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!