[Neuroimaging] Nibabel API change - always read as float

Matthew Brett matthew.brett at gmail.com
Tue Jul 21 01:22:00 CEST 2015


On Mon, Jul 20, 2015 at 11:42 PM, Alexis Roche <alexis.roche at gmail.com> wrote:
>> Can you think of a common use of an arbitrary dtype here?  I mean
>> dtype not equal to the on-disk dtype or the scaled dtype?   It seems
>> as if that use might be rather specialized - could it be done in the
>> user code that starts with the code above?
> Right. I can think of the following cases:
> * a mask image encoded in int16 on disk, but you want an array of booleans
> in memory (nifti does not support boolean format)

I guess you can assume no scalefactors?  Then:

data = img.get_data(as_float=False).astype(np.bool)

That is as memory-efficient as you can do that, I think.

> * an image of positive-valued MR parameters encoded in int, but you want
> unsigned int in memory

> Of course, that could be done via the 'dataobj' attribute, which requires
> advanced knowledge of nibabel I think. I don't think this is very
> specialized usage.

Same idea if no scalefactors.  If you do have scalefactors, and you
don't want them applied, yes, you'll have to use
`img.dataobj.get_unscaled()` for that, but it does seem pretty
specialized to throw away scalefactors in that situation.

Or did you mean that `get_data` also has to take care only to load
small parts of the image at a time, and apply scalefactors, and then
cast that part of the array?



More information about the Neuroimaging mailing list