In [ ]:
import ipyvolume as ipv
import numpy as np
from matplotlib.pyplot import cm

In [ ]:
# download the dataset
!wget -q https://www.dropbox.com/s/eqht79b7j4jqit2/petct.npz?dl=1 -O petct.npz

We show a CT scan and overlay the PET scan


In [ ]:
full_scan = {k: v.swapaxes(0, 1)[::-1] for k,v in np.load('petct.npz').items()}
print(list(full_scan.keys()))

In [ ]:
table_ct = cm.gray_r(np.linspace(0, 1, 255))
table_ct[:50, 3] = 0 # make the lower values transparent
table_ct[50:, 3] = np.linspace(0, 0.05, table_ct[50:].shape[0])
tf_ct = ipv.TransferFunction(rgba=table_ct)

In [ ]:
ct_vol = ipv.quickvolshow(full_scan['ct_data'], 
                          tf=tf_ct, lighting=False, 
                          data_min=-1000, data_max=1000)
ct_vol

Zoom

Zoom in by clicking the magnifying icon, or keep the alt/option key pressed. After zooming in, the higher resolution verion cutout will be displayed.

Multivolume rendering

Since version 0.5, ipyvolume supports multivolume rendering, so we can render two volumetric datasets at the same time.


In [ ]:
table_pet = cm.hot(np.linspace(0, 1, 255))
table_pet[:50, 3] = 0 # make the lower values transparent
table_pet[50:, 3] = np.linspace(0, 1, table_pet[50:].shape[0])
tf_pet = ipv.TransferFunction(rgba=table_pet)

In [ ]:
pet_vol = ipv.volshow(full_scan['pet_data'], 
            tf=tf_pet, 
            data_min=0, 
            data_max=10)

In [ ]:
pet_vol.rendering_method='MAX_INTENSITY'

In [ ]:
table_lab = np.array([
    [0,0,0,0],
    [0,1,0,1]
])
tf_lab = ipv.TransferFunction(rgba=table_lab)
lab_vol = ipv.volshow(full_scan['label_data']>0, 
            tf=tf_lab, 
            data_min=0, 
            data_max=1)