Render segmentation stored in a NumPy array with VTK
I have a segmentation in 3D numpy.ndarray that I would like to display in VTK. [Cm. There's a 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) Store the NumPy array in a Nifiti file using nib. Nifti1Image (2) Load the Nifiti file into vtk with (vtkNIFTIImageReader ()) (3) Display surface with vtkDiscreteMarchingCubes ()
My question is how to convert this 3D NumPy array directly to VTK without an intermediate file.
source to share
You can use the numpy_support module ( https://github.com/Kitware/VTK/blob/master/Wrapping/Python/vtk/util/numpy_support.py ) or the new vatk 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/
In fact, while I was looking for an example, I also found http://www.vtk.org/Wiki/VTK/Examples/Python/vtkWithNumpy , which I have never tried before!
source to share