NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.volumeutils.allopen

Next topic

nibabel.volumeutils.array_from_file

Reggie -- the one

nibabel.volumeutils.apply_read_scaling

nibabel.volumeutils.apply_read_scaling(arr, slope=1.0, inter=0.0)

Apply scaling in slope and inter to array arr

This is for loading the array from a file (as opposed to the reverse scaling when saving an array to file)

Return data will be arr * slope + inter. The trick is that we have to find a good precision to use for applying the scaling. The heuristic is that the data is always upcast to the higher of the types from arr, `slope, inter if slope and / or inter are not default values. If the dtype of arr is an integer, then we assume the data more or less fills the integer range, and upcast to a type such that the min, max of arr.dtype * scale + inter, will be finite.

Parameters :

arr : array-like

slope : scalar

inter : scalar

Returns :

ret : array

array with scaling applied. Maybe upcast in order to give room for the scaling. If scaling is default (1, 0), then ret may be arr ret is arr.