# Requirements
# !pip install nibabel vtk
import k3d
import math
import numpy as np
import nibabel as nib
from k3d.helpers import download
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)
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()
embryo = k3d.mip(volume_data.astype(np.float16),
color_map=np.array(k3d.basic_color_maps.BlackBodyRadiation, dtype=np.float32),
bounds=bounds)
plot = k3d.plot(background_color=0, grid_visible=False)
plot += embryo
plot.display()
plot.lighting = 0
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()
volume.samples = 1024.0
volume.color_range = [650, 1500]