[Neuroimaging] Nibabel API change - always read as float

Matthew Brett matthew.brett at gmail.com
Wed Jul 22 01:15:12 CEST 2015


Hi,

On Tue, Jul 21, 2015 at 11:38 PM, Satrajit Ghosh <satra at mit.edu> wrote:
> hi matthew,
>
> does the image object (dataobj.slope) store the raw slope value from the
> header, not the effective slope value? i.e. is there a way for me to detect
> that the slope in the nifti file is 0.

It stores the effective slope value, so there's no current way to
detect a slope of 0.   You would have to read the header again, I'm
afraid.   SPM does the same thing, as far as I can see - it sets the
slope in the read image to 1 when it is 0 in the header.

In [1]: import nibabel as nib
In [2]: nib.Nifti1Header.from_fileobj(open('scale_zero.nii'))['scl_slope']
Out[2]: array(0.0, dtype=float32)
In [3]: nib.Nifti1Header.from_fileobj(open('scale_one.nii'))['scl_slope']
Out[3]: array(1.0, dtype=float32)

>> img = nifti('scale_zero.nii'); disp(img.dat)
        fname: 'scale_zero.nii'
          dim: [2 3 4]
        dtype: 'INT64-LE'
       offset: 352
    scl_slope: 1
    scl_inter: 0

>> img = nifti('scale_one.nii'); disp(img.dat)
        fname: 'scale_one.nii'
          dim: [2 3 4]
        dtype: 'INT64-LE'
       offset: 352
    scl_slope: 1
    scl_inter: 0

I don't know of any software that does behave differently for
scl_slope of 0 or 1 - but I'd certainly like to know if there is any.

> conversely, when saving an image is there an explicit way of saving with
> slope == 0, and keeping the dtype as the same as arr.dtype whenever that
> dtype is allowed in nifti-1/2.

You can set the slope manually to 0 if you like, and of course you can
set the dtype manually too.  The header dtype gets set to the dtype of
the array by default, if you do not create the image with a header.

Cheers,

Matthew


More information about the Neuroimaging mailing list