nibabel

Read / write access to some common neuroimaging file formats

This package provides read +/- write access to some common medical and neuroimaging file formats, including: ANALYZE (plain, SPM99, SPM2 and later), GIFTI, NIfTI1, NIfTI2, CIFTI-2, MINC1, MINC2, AFNI BRIK/HEAD, MGH and ECAT as well as Philips PAR/REC. We can read and write FreeSurfer geometry, annotation and morphometry files. There is some very limited support for DICOM. NiBabel is the successor of PyNIfTI.

The various image format classes give full or selective access to header (meta) information and access to the image data is made available via NumPy arrays.

Website

Current documentation on nibabel can always be found at the NIPY nibabel website.

Mailing Lists

Please send any questions or suggestions to the neuroimaging mailing list.

Code

Install nibabel with:

pip install nibabel

You may also be interested in:

License

Nibabel is licensed under the terms of the MIT license. Some code included with nibabel is licensed under the BSD license. Please see the COPYING file in the nibabel distribution.

Citing nibabel

Please see the available releases for the release of nibabel that you are using. Recent releases have a Zenodo Digital Object Identifier badge at the top of the release notes. Click on the badge for more information.

Quickstart

import nibabel as nib

img1 = nib.load('my_file.nii')
img2 = nib.load('other_file.nii.gz')
img3 = nib.load('spm_file.img')

data = img1.get_data()
affine = img1.affine

print(img1)

nib.save(img1, 'my_file_copy.nii.gz')

new_image = nib.Nifti1Image(data, affine)
nib.save(new_image, 'new_image.nii.gz')

For more detailed information see the NiBabel Manual.

get_info()

setup_package()

Set numpy print style to legacy=”1.13” for newer versions of numpy

teardown_package()

Reset print options when tests finish

get_info

nibabel.get_info()

setup_package

nibabel.setup_package()

Set numpy print style to legacy=”1.13” for newer versions of numpy

teardown_package

nibabel.teardown_package()

Reset print options when tests finish