Numpy 3D array into VTK data types for volume rendering?

Here is a full example of how to create a volume (vtkImageData) from a numpy array. The code supports scalar, vector, and tensor volumes. If you don’t use this from 3D Slicer then you need to change how you set the image spacing (you need to set it using vtkImageData.SetSpacing):

Note that you can get static or interactive (you can rotate around with your mouse) 3D volume rendering from numpy arrays directly in your Jupyter notebook by choosing 3D Slicer as kernel.

1 Like