[Neuroimaging] 2D NIFTI images in nibabel

Reid, Robert I. (Rob) Reid.Robert at mayo.edu
Thu Sep 1 10:17:27 EDT 2016

Well, no.

I usually work with a mix of 3D and 4D NIFTIs, and like that the 3D ones appear as 3D arrays instead of 4D (or 5D, 6D,…) with the extra axis having length 1.

Also, if I select a volume from a 4D array, i.e.
vol = data[…, t],
it makes sense that I get a 3D array, just like selecting an element from a list of scalars gives you a scalar.

I understand that there are two ways of looking at it, but I think overall things are better as is.


Robert I. Reid, Ph.D. | Sr. Analyst/Programmer, Information Technology
Aging and Dementia Imaging Research | Opus Center for Advanced Imaging Research
Mayo Clinic | 200 First Street SW | Rochester, MN 55905 | mayoclinic.org<http://www.mayoclinic.org/>

From: Neuroimaging [mailto:neuroimaging-bounces+reid.robert=mayo.edu at python.org] On Behalf Of paul mccarthy
Sent: Thursday, September 01, 2016 4:15 AM
To: Neuroimaging analysis in Python
Subject: [Neuroimaging] 2D NIFTI images in nibabel

Howdy all,

Nibabel truncates the third dimension of a NIFTI image with dim3=1.

(boo) ws189:nifti2D paulmc$ fslinfo MNI152_T1_2mm_sliceXY.nii.gz
data_type      INT16
dim1           91
dim2           109
dim3           1
dim4           1
datatype       4
pixdim1        2.000000
pixdim2        2.000000
pixdim3        2.000000
pixdim4        1.000000
cal_max        8000.0000
cal_min        3000.0000
file_type      NIFTI-1+

(boo) ws189:nifti2D paulmc$ ipython
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 12:54:16)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import nibabel as nib

In [2]: i = nib.load('MNI152_T1_2mm_sliceXY.nii.gz')

In [3]: i.shape
Out[3]: (91, 109)

In [4]: i.header.get_zooms()
Out[4]: (2.0, 2.0)

In [5]:

Does anybody else think that this is a problem?

Note that the dimensions for an image of e.g. size (91, 1, 91) will be preserved.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160901/9a4edc46/attachment.html>

More information about the Neuroimaging mailing list