The easiest way to view volumetric images in Python 👩💻 Install it via pip install niftiview
!
niftiview
stands behind
- NiftiView, the viewer app with the cutest desktop icon 🧠 Download it here!
- NiftiWidget, a widget for interactive viewing in Jupyter 👩💻🧠 Install it via
pip install niftiwidget
!
Single images can be shown via NiftiImage
from niftiview import TEMPLATES, NiftiImage
nii = NiftiImage(TEMPLATES['ch2'])
# nii = NiftiImage('/path/to/your/nifti.nii.gz')
im = nii.get_image()
im.show()
NiftiImageGrid
can display multiple images in a nice grid layout
from niftiview import TEMPLATES, NiftiImageGrid
niigrid = NiftiImageGrid([TEMPLATES['ch2'], TEMPLATES['T1']])
# niigrid = NiftiImageGrid(['/path/to/your/nifti1.nii.gz',
# '/path/to/your/nifti2.nii.gz'])
im = niigrid.get_image(layout='sagittal++', nrows=1)
im.show()
Behind the scenes, niftiview
uses three main classes that build on each other
NiftiCore
: Puts image slices of the 3D image in a 2Dnumpy.ndarray
...NiftiImage
: ...applies a colormap to the array, converts it to aPIL.Image
and adds overlays...NiftiImageGrid
: ...puts the images in a grid
To fully understand how to use niftiview
, study the example notebooks 🧑🏫
examples/0_core.ipynb
explainingNiftiCore
examples/1_image.ipynb
explainingNiftiImage
examples/2_grid.ipynb
explainingNiftiImageGrid
pip install niftiview
also installs the command line utility that given filepath(s) or a filepattern...
niftiview-cli -i /path/to/niftis/*.nii.gz -o /path/to/output/folder --gif
...saves PNGs or GIFs. To showcase its versatility, here is a compilation of created GIFs
Explore all the available options by running niftiview-cli --help
P.S. If you're interested in creating 🧠 tissue maps like the ones shown at the end of the GIF, check out deepmriprep!