I am saving some nparray into nifti format using nibabel
package. I specify a slope and intercept value in order to scale data back to their original format. However, the scale and intercept information are not available anymore when I load back the data. Here is a code snippet to reproduce the behavior:
import numpy as np
import nibabel as nib
# Create dumb 3D data:
img=np.ones((20,20,5),dtype=np.uint16)
# Create an affine matrix:
affine=np.eye(4)
# Create nifti
nii=nib.Nifti1Image(img,affine=affine)
# Set slope and inter values
nii.header.set_slope_inter(slope=1,inter=0)
# Save the nifti on disk
nib.save(nii,'test.nii')
# Load back the data
nii2=nib.load('test.nii')
# Get the slope and inter
print(nii2.header.get_slope_inter())
# It returns (None, None)
The output is (None,None)
, despite the fact that nii2.header.has_data_slope
and nii2.header.has_data_intercept
both return True.
I opened the nifti file with other nifti reader such as mango and itk-snap, and could check that the slope and intercept are correctly displayed.
Is this a bug?
Thanks for the help!