[Neuroimaging] change nifti header in nibabel
Ze Wang
redhatw at gmail.com
Wed Jun 16 10:34:34 EDT 2021
Hi, Does anyone know how to change the dimension of the nifti image
and save back to disk? My nifti files should be a 4D image but my c++
code wrongly set the dimensionality to be 3 rather than 4. The data
were saved correctly and can be read using mricron. Certainly, FSL and
SPM and nibabel can all only read the first volume.
I tried the following way to read the data using nibabel:
v=nib.load('file.nii.gz')
v.header['dim'][0]=4
dat=v.get_fdata()
But it still failed to read the 4D data. My question is: 1. how to let
nibabel know that the updated header information should be used when
read data? 2. how to save the new header back to the file without
loading the data?
Thanks
Ze
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20210616/14992d6b/attachment.html>
More information about the Neuroimaging
mailing list