In [1]:
import k3d
import math
import numpy as np
import nibabel as nib
from k3d.helpers import download
In [2]:
import vtk
from vtk.util import numpy_support

filename = download('https://github.com/marcomusy/vtkplotter/raw/master/vtkplotter/data/embryo.slc')
reader = vtk.vtkSLCReader()
reader.SetFileName(filename)
reader.Update()
vti = reader.GetOutput()

bounds = vti.GetBounds()
x, y, z = vti.GetDimensions()
volume_data = numpy_support.vtk_to_numpy(vti.GetPointData().GetArray(0)).reshape(-1, y, x)
In [3]:
embryo = k3d.volume(volume_data.astype(np.float16), 
                    color_map=np.array(k3d.basic_color_maps.BlackBodyRadiation, dtype=np.float32), 
                    bounds=bounds)

plot = k3d.plot()
plot += embryo
plot.display()
/Users/marcin/anaconda3/lib/python3.7/site-packages/traittypes/traittypes.py:101: UserWarning: Given trait value dtype "float16" does not match required type "float32". A coerced copy has been created.
  np.dtype(self.dtype).name))
In [ ]:
filename = download('https://github.com/FNNDSC/data/raw/master/nifti/adi_brain/adi_brain.nii.gz')

nii_source = nib.load(filename)
img = nii_source.get_fdata()
dx, dy, dz = nii_source.header.get_zooms()
img = np.swapaxes(img,0,2).astype(np.float32)
nz, ny, nx = img.shape

volume = k3d.volume(img, color_range=[50,1000], color_map=np.array(k3d.basic_color_maps.Jet, dtype=np.float32))

plot = k3d.plot()
plot += volume
plot.display()
In [ ]:
volume.samples = 1024.0
In [ ]:
volume.color_range = [650,1500]
In [ ]: