%matplotlib inline # load modules import numpy as np import SimpleITK as sitk import sys sys.path.append('../src') import volumerendering import imagedisplay # Read the image image = sitk.ReadImage('../sample_data/image2.nii.gz' ) # Image dimensions (width,height,depth) imageSize = image.GetSize() # Several 2-D projections along the same axis imagedisplay.myshow3d( image, yslices=range(50,imageSize[2]-50,12), zslices=range(50,imageSize[2]-50,12), dpi=10 ) # Read the image image = sitk.ReadImage('../sample_data/image.nii.gz') # Image dimensions (width,height,depth) imageSize = image.GetSize() # 3D planar view slices =[ image[imageSize[0]/2,:,::-1], image[:,imageSize[1]/2,::-1], image[:,:,imageSize[2]/2] ] imagedisplay.myshow(sitk.Tile(slices, [3,1]), title="Image", dpi=30) # Load the annotations (gray matter, white matter, csf) img_labels = sitk.ReadImage('../sample_data/labelmap.nii.gz') # Display the annotations slices = [ img_labels[imageSize[0]/2,:,::-1], img_labels[:,imageSize[1]/2,::-1], img_labels[:,:,imageSize[2]/2] ] imagedisplay.myshow(sitk.Tile(slices, [3,1]), title="Segmentation", dpi=30) # load the second image image2 = sitk.ReadImage('../sample_data/image2.nii.gz') data = sitk.GetArrayFromImage(image2) # numpy array # converting the pixel type to uint8 and rescaling data = data.astype('float') data /= data.max() data *= 255 data = data.astype('uint8') # intensity window and opacity value win_b = 39.0 win_e = 72.0 win_m = (win_b+win_e)/2 opacity = 0.2 # volume rendering transfer function tf = [ [0,0,0,0,0], [win_b,0,0,0,0], [win_m,1,1,1,0.2], [win_e,1,1,1,0], [data.max(),1,1,1,0] ] # perform volume rendering (a new window should be opened - vtk inline display is not supported) actor_list = volumerendering.volumeRender( data, tf=tf, spacing=image2.GetSpacing() ) volumerendering.vtk_basic( actor_list, embed=True ) # embed = True: displays a screenshot in the notebook # embed = False: interactive VTK window