[Neuroimaging] Nibabel get_fdata()

Nate Vack njvack at wisc.edu
Wed Oct 17 10:12:57 EDT 2018


The docs:
http://nipy.org/nibabel/reference/nibabel.dataobj_images.html#nibabel.dataobj_images.DataobjImage.get_data

say that get_data() is deprecated, and the forward-compatible way to get at
your data without casting would be:

import nibabel as nib
import numpy as np

data = nib.load('wBOLD.nii')
data_arr = np.asanyarray(data.dataobj)

For some reason, that seems to be returning an array made completely of
nan, though, which is weird?

Any operations on a 60G array will, of course, be pretty slow.

Aside: It might be useful for there to be a get_data_without_cast() method
or such; the np.asanyarray() trick is not particularly intuitive. I
remember this question came up here before, though, so maybe there's a
reason that's a bad idea...

-n

On Wed, Oct 17, 2018 at 7:20 AM serafim loukas <seralouk at hotmail.com> wrote:

> Hello,
>
>
> The images are on my local HD.
> The file is around 60GB.
>
> Here is my code to demonstrate this:
>
> *import nibabel as nib*
>
> *data = nib.load('wBOLD.nii')*
> *slices_fast = data.get_data()[:,:,:,0]*
> *slices_slow = data.get_fdata()[:,:,:,0]*
>
> And here you can find the file compressed:
> https://drive.google.com/open?id=1BkClOxytqUKtv5Zt7fMr2P-kvzJ5OKS0
>
>
> I was thinking to use *get_data() instead of get_fdata() *and then
> conduct some analysis.
> In this case, what is the difference between the 2 commands ?
>
>
> Best,
> Serafim
>
>
> On 17 Oct 2018, at 12:49, Matthew Brett <matthew.brett at gmail.com> wrote:
>
> Hi,
>
> Can you post an image somewhere for us to try?
>
> Are your images on your local hard disk?
>
> Cheers,
>
> Matthew
> On Wed, Oct 17, 2018 at 10:07 AM serafim loukas <seralouk at hotmail.com>
> wrote:
>
>
> Dear Experts,
>
>
>
> I have some neuroimaging data and I would like to use Nibabel instead of
> SPM (matlab).
> My goal is to load brain images, then vectorise them and finally do some
> analysis on these vectors.
>
> When I use the get_fdata() command, it takes a lot of time to load the
> image.
> On the other hand, SPM is faster (spm_read_vols(spm_vol(my_image_path)))
> in terms of loading the data.
>
> Am I missing something? Is there any way to make get_fdata() faster?
>
>
>
> Best,
> Serafim
> _______________________________________________
> 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
>
>
> _______________________________________________
> 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/20181017/bfea15bc/attachment.html>


More information about the Neuroimaging mailing list