I'm trying to strip MRI images but I can't understand this part of the code. Specifically:
for i in range(nii_images.shape[2]):
data = nii_images[:,:,i]
print(i)
an MRI image stripped.
I'm trying to strip MRI images but I can't understand this part of the code. Specifically:
for i in range(nii_images.shape[2]):
data = nii_images[:,:,i]
print(i)
an MRI image stripped.
First, we need to understand what the loop is looping on:
for i in range(nii_images.shape[2]):
nii.images
appears to be a class, and then .shape
is perhaps an array in that class. It seems to be an array of arrays, because we then get the third element ([2]
) and we loop on that.
.
Next, I think it is the slicing that you are having trouble with.
data = nii_images[:,:,i]
Are you using numpy? Because this looks like another post. Or here. Or over here
It seems to select a column of a 2d data set. It seems like an odd way of doing it though. As Dan D. says,
It extracts the 2d slices of the 3d array along its third dimension. For an image these tend to be the color component channels.
Some output would be really helpful here to understand the data further. Also, is there any reason why you need to understand the code? Could you look at the documentation?