[Neuroimaging] Nibabel API change - always read as float
Matthew Brett
matthew.brett at gmail.com
Tue Jul 21 20:55:39 CEST 2015
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
More information about the Neuroimaging
mailing list