I am creating image from a numpy array, using itk-python, and I see that it reorders the array axes:
print("Array shape: "+str(scanArray.shape))
scanVolume = itk.GetImageFromArray(scanArray)
print("Image shape: "+str(scanVolume.GetLargestPossibleRegion().GetSize()))
Result:
Array shape: (512, 512, 133)
Image shape: itkSize3 ([133, 512, 512])
So I then thought I can swap axes to take care of this, but the result is not what I was expected:
print("Array shape: "+str(scanArray.shape))
scanArray = np.swapaxes(scanArray,0,2)
print("Array shape reoriented: "+str(scanArray.shape))
scanVolume = itk.GetImageFromArray(scanArray)
print("Image shape: "+str(scanVolume.GetLargestPossibleRegion().GetSize()))
Result:
Array shape: (512, 512, 133)
Array shape reoriented: (133, 512, 512)
Image shape: itkSize3 ([133, 512, 512])
I don’t understand what is happening here, and why the shape of the ITK image does not change although I change the numpy array shape.
Can someone help what is the proper way to re-shape the array here?