[Neuroimaging] NILEARN - WHY THIS CODE THROWS AN ERROR?????
Matthew Brett
matthew.brett at gmail.com
Fri Jul 8 09:26:24 EDT 2022
Hi,
On Fri, Jul 8, 2022 at 2:05 PM נתי שטרן <nsh531 at gmail.com> wrote:
>
> fullcode:
>
>
>
> import nilearn.plotting as plot
> import os,gzip,io
> import nibabel as nib
> path="C:/users/administrator/desktop/nii"
> path2="C:/users/administrator/desktop/nii/out/"
> for i in os.listdir(path):
> if(".nii.gz" in i):
> pass
> else:
>
> if(".nii" in i):
> img = nib.load(path+"/"+i)
> data = img.get_fdata()
> print(data)
> import imageio
> X=0
> for s in data:
> import numpy
> aleph=numpy.array(s,dtype=numpy.int8)
> X=X+1
> plot.plot_img(aleph)
>
> imageio.imwrite("C:\\users\\administrator\\desktop\\nii\\"+i+str(X)+'.jpg', s)
>
>
>
>
>
>
> error:
> Data given cannot be loaded because it is not compatible with nibabel format
Honestly - I wouldn't email python-list - this is a neuroimaging question.
The obvious debugging step here is to see what "path+"/"+i" is. Is it
in fact a filename of a nifti image? Try loading it in some other
Nifti reader. If you get stuck, put the file up somewhere where we
can get it and try loading it.
Cheers,
Matthew
More information about the Neuroimaging
mailing list