[Neuroimaging] Nibabel API change - always read as float

Matthew Brett matthew.brett at gmail.com
Wed Jul 8 16:18:47 CEST 2015

On Wed, Jul 8, 2015 at 3:36 AM, Satrajit Ghosh <satra at mit.edu> wrote:
> hi matthew,
> quick follow up question on proposed change. would saving the image back to
> disk restore the original datatype? i.e. i read a uint8 image and save it to
> another location, would that new file by 8 times the size of the original
> file?

If the image to be saved was created with a header, then save uses the
defined dtype in the header.  If it was defined without a header, then
save uses the array dtype to save the data.

If you load and the save an int8 image with not-default scaling, the
image has a defined header with dtype int8, but the in-memory dtype
will be float, because of the scaling.   When saving, nibabel
calculates the optimal scalefactors for the floating point array,
where optimal means using all of the output data range from -128 to
127.   This might well be different from the scaling in the loaded
image.   Nibabel does this because you might have changed the
in-memory array so we can't depend on the previous scaling being

See you,


More information about the Neuroimaging mailing list