2

I have dataset of nii.gz files each around 1G including 4d tensor. There are two ways of reading them that I am aware of as the following:

img = nib.load('fMRI.nii.gz')
imgarr = np.array(img.dataobj)

or

img = nib.load('fMRI.nii.gz')
imgarr = img.get_data()

the problem is reading the whole tensor is expensive and I just need an slice. Is there any other way?

Saeed
  • 598
  • 10
  • 19

1 Answers1

3

Actually you do not need to load anything of the main image data into the memory.

img = nib.load('fMRI.nii.gz')
 
# get the first 10 slices
img.slicer[0:10]

#verify selection
img.slicer[0:10].shape
seralouk
  • 30,938
  • 9
  • 118
  • 133