#!/usr/bin/env python # coding: utf-8 # In[ ]: # Requirements # !pip install nibabel vtk # In[ ]: import k3d import math import numpy as np import nibabel as nib from k3d.helpers import download # In[ ]: import vtk from vtk.util import numpy_support filename = download('https://github.com/marcomusy/vtkplotter-examples/raw/master/vtkplotter_examples/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[ ]: 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() # 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[ ]: