[Neuroimaging] Nibabel get_fdata()

Matthew Brett matthew.brett at gmail.com
Wed Oct 17 10:03:13 EDT 2018


Hi,
On Wed, Oct 17, 2018 at 1:20 PM 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 ?

I'm guessing from the above, that you're getting better performance
from `get_data`.  This is because, in your case, you have a 32-bit
float image, that doesn't have any scalefactors, so the optimized path
for you, is to use a memory mapped version of the array.  This is what
happens for `get_data`, but for various reasons, `get_fdata` always
returns 64-bit floats, so inflating memory, and making it impossible
to use memory mapping (because the image data type is not the same).

Cheers,

Matthew


More information about the Neuroimaging mailing list