[Neuroimaging] Nibabel API change - always read as float

Satrajit Ghosh satra at mit.edu
Wed Jul 22 00:38:27 CEST 2015


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.

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.

cheers,

satra

On Tue, Jul 21, 2015 at 2:55 PM, Matthew Brett <matthew.brett at gmail.com>
wrote:

> On Tue, Jul 21, 2015 at 7:28 PM, Brendan Moloney <moloney at ohsu.edu> wrote:
> >
> >> Yes, I guess you would have to either go through float64 or handle the
> >> scaling yourself.  But isn't that just:
> >>
> >> data = data.astype(np.float32) * scale + inter?
> >
> > If you just want your code to work with Nifti then I think the full code
> would be something like:
> >
> > data = img.get_data(as_float=False)
> > slope = img.dataobj.slope
> > if np.isnan(slope) or slope == 0:
> >     slope = 1.0
> > inter = img.dataobj.inter
> > if np.isnan(inter):
> >     inter = 0.0
> > data = data.astype(np.float32) * scale + inter
>
> Actually, because of the slope, inter processing in the dataobj, I
> think you'll find you can do:
>
> data = np.array(img.dataobj).astype(np.float32) * dataobj.slope +
> dataobj.inter
>
> > If you want your code to work with other image types besides Nifti I
> guess this gets slightly more complex.
> >
>
> Yes, that's a reasonable point, it would be horrible with MINC for example.
>
> Cheers,
>
> Matthew
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20150721/97e7f073/attachment.html>


More information about the Neuroimaging mailing list