Hi,
Your img is 4-Dimensional data. This can be checked using:
img.header.get_data_shape()
For my MRI data the resulting shape is (height, width, depth, sequence). Nibabel recommends accessing the data as an array using:
image_data = img.get_fdata()
This will still result in 4D data. If you want to process your images in 2D or 3D you can slice into this. Alternatively, you can used the 4D tensor from the dataset
and use the dataloader
to create a 5D tensor as discussed here pytorch.
Hope this helps.
James.