[Neuroimaging] code

Matthew Brett matthew.brett at gmail.com
Tue Jul 6 16:59:10 EDT 2021


Hi,

On Tue, Jul 6, 2021 at 9:53 PM Rimsha Mahrukh <rimsham97 at gmail.com> wrote:
>
> Respected Sir/Madam,
>
> I am sending you this mail because I needed some help with implementation. I want to extract the first 30 mins from my FMRI bold run which is in 'nii' format. As I apply the get_fdata() function on it I get a memory error. I would be very thankful if you can guide me with this please.

Did you find:

https://nipy.org/nibabel/images_and_memory.html

?   Say your TR was 2 seconds, then the first 30 minutes are:

n_trs = int(30 * 60 / 2)

Then:

import nibabel as nib

# Does not load image into memory
img = nib.load('my_image.nii')

# Slice data object, still does not read into memory
data_30 = img.dataobj[..., :n_trs]

# Make a new image object
img_30 = nib.Nifti1Image(data_30, img.affine, img.header)

# Load these data
img_arr = img_30.get_fdata()

Does that work?

Cheers,

Matthew


More information about the Neuroimaging mailing list