[Neuroimaging] nibabel: probelm reading a nii.gz
Gabriel Reynés
greynell at gmail.com
Wed Jul 26 07:08:04 EDT 2017
Problem solved, worked wonderfully, thanks!
Cheers,
Gabriel
On Mon, Jul 24, 2017 at 8:19 PM, Matthew Brett <matthew.brett at gmail.com>
wrote:
> Hi,
>
> 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
> error
> data = hdr.data_from_fileobj(fobj)
> hdr['magic'] = b'n+1\x00'
> img = nib.Nifti1Image(data, None, hdr)
> nib.save(img, 'fixed.nii.gz')
> """
>
> Cheers,
>
> Matthew
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20170726/aac8cf3e/attachment.html>
More information about the Neuroimaging
mailing list