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

נתי שטרן nsh531 at gmail.com
Fri Jul 8 11:38:59 EDT 2022


Its cool.
I'll try this on sunday

בתאריך יום ו׳, 8 ביולי 2022, 17:56, מאת Christophe Pallier ‏<
christophe at pallier.org>:

> You can pass a filename directly to plot_img (there is no need to use
> nibabel, numpy, etc. to extract data).
>
>  Also you can save the figure without imagio, using  savefig() from
> matplotlib or even directly from nilearn (see examples in its doc)
>
>
>
>
>
>
> On Fri, Jul 8, 2022, 16:35 נתי שטרן <nsh531 at gmail.com> wrote:
>
>> HOW TO DO THIS?
>> I'm new in numpy :)
>>
>> ‫בתאריך יום ו׳, 8 ביולי 2022 ב-16:55 מאת ‪Christopher Markiewicz‬‏ <‪
>> markiewicz at stanford.edu‬‏>:‬
>>
>>> 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‬‏>:‬
>>>
>>> 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
>>> _______________________________________________
>>> Neuroimaging mailing list
>>> Neuroimaging at python.org
>>> https://mail.python.org/mailman/listinfo/neuroimaging
>>>
>>>
>>>
>>> --
>>> <https://netanel.ml>
>>> _______________________________________________
>>> Neuroimaging mailing list
>>> Neuroimaging at python.org
>>> https://mail.python.org/mailman/listinfo/neuroimaging
>>>
>>
>>
>> --
>> <https://netanel.ml>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20220708/f49c02d1/attachment.html>


More information about the Neuroimaging mailing list