pythonpytorchmedical-imaging

I have nii.gz volume and I need to display it as one image


I have nii.gz volume and I need to display it as one image. I could display one slice as shown below.

mri_file = '/tmp/out_img/case0001_gt.nii.gz'
img = nib.load(mri_file)
mg_data = img.get_fdata()
mid_slice_x = img_data[ :, :,119]
plt.imshow(mid_slice_x.T, cmap='gray', origin='lower')
plt.xlabel('First axis')
plt.ylabel('Second axis')
plt.colorbar(label='Signal intensity')
plt.show()

enter image description here

But I need to display the whole volume as one image with different color maps as show below.

enter image description here


Solution

  • Me and some colleagues have made a library that provides some nice functionality for visualising medical images.

    It is called platipy, and can be installed via PyPI:

    pip install platipy
    

    It can display scalar maps (like you asked for), for example:

    from platipy.imaging import ImageVisualiser
    
    # read in image using SimpleITK (included with platipy)
    img = sitk.ReadImage("IMAGE.nii.gz")
    labelmap = sitk.ReadImage("LABELS.nii.gz")
    
    vis = ImageVisualiser(img, axis="z", cut=77, figure_size_in=6)
    vis.add_scalar_overlay(labelmap, colormap=plt.cm.jet, discrete_levels=3, show_colorbar=False)
    fig = vis.show()
    

    This will give you something like:

    axial_slice

    Hope this helps!