[Neuroimaging] nibabel: probelm reading a nii.gz
greynell at gmail.com
Wed Jul 26 07:08:04 EDT 2017
Problem solved, worked wonderfully, thanks!
On Mon, Jul 24, 2017 at 8:19 PM, Matthew Brett <matthew.brett at gmail.com>
> On Mon, Jul 24, 2017 at 6:39 PM, Reynolds, Richard C. (NIH/NIMH) [E]
> <reynoldr at mail.nih.gov> wrote:
> > Hi Gabriel,
> > It is simple to modify with the nifti_tool program (from
> > the nifticlib library), but I don't know whether you have
> > that, e.g.
> > nifti_tool -mod_hdr -mod_field magic 'n+1' \
> > -infiles C1_Rel_thres40.0.nii -prefix NEW.nii
> Thanks - that's one easy way to do the fix.
> If you wanted to use nibabel, you could also do the following:
> import nibabel as nib
> fname = 'C1_Rel_thres40.0.nii.gz'
> # The following just selects the right object to open the file - in
> # this case zipfile.ZipFile
> with nib.openers.Opener(fname) as fobj:
> hdr = nib.Nifti1Header.from_fileobj(fobj, check=False) # don't raise
> data = hdr.data_from_fileobj(fobj)
> hdr['magic'] = b'n+1\x00'
> img = nib.Nifti1Image(data, None, hdr)
> nib.save(img, 'fixed.nii.gz')
> Neuroimaging mailing list
> Neuroimaging at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Neuroimaging