[Neuroimaging] NILEARN - WHY THIS CODE THROWS AN ERROR?????

Christopher Markiewicz markiewicz at stanford.edu
Fri Jul 8 09:40:35 EDT 2022


A lack of traceback makes it difficult to see where the error is occurring, but I believe the issue is that you're passing a numpy array to a nilearn function that expects an image.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Neuroimaging <neuroimaging-bounces+markiewicz=stanford.edu at python.org> on behalf of נתי שטרן <nsh531 at gmail.com>
Sent: Friday, July 8, 2022 9:38:57 AM
To: Neuroimaging analysis in Python <neuroimaging at python.org>
Subject: Re: [Neuroimaging] NILEARN - WHY THIS CODE THROWS AN ERROR?????

it's a fullpath to nifti image

‫בתאריך יום ו׳, 8 ביולי 2022 ב-16:27 מאת ‪Matthew Brett‬‏ <‪matthew.brett at gmail.com<mailto:matthew.brett at gmail.com>‬‏>:‬
Hi,

‪On Fri, Jul 8, 2022 at 2:05 PM ‫נתי שטרן‬‎ <nsh531 at gmail.com<mailto: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
_______________________________________________
Neuroimaging mailing list
Neuroimaging at python.org<mailto:Neuroimaging at python.org>
https://mail.python.org/mailman/listinfo/neuroimaging


--
[https://ci3.googleusercontent.com/mail-sig/AIorK4ykFjL1iagUdlm0jcadJlaq1KyDf5c3YeE3nLFugFyn69aRMAcHd2OKO51XtKIvhzIdbuX81XE]<https://netanel.ml>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20220708/d1f71e28/attachment.html>


More information about the Neuroimaging mailing list