Enforcing same orientation of image every time

For a Python scripted module, I am loading a series of DICOM images for a DCE MR image into a volume with this syntax:

plugin = slicer.modules.dicomPlugins['DICOMScalarVolumePlugin']()
loadables = plugin.examine([files])
volume = plugin.load(loadables[0])
volumeArray=slicer.util.arrayFromVolume(volume)

For most MR exams, the variable volume orders the axial slices such that the first slice is closest to the patient’s foot and the last slice is closest to the patient’s head. However, for some exams, volume sorts the slices in the opposite order of this, with first slice closest to head and last slice closest to foot.
In my code, I want to be able to identify when volume has the Head --> Foot orientation so that I can force the image to have the Foot --> Head orientation instead.
How can I do this? Is there any particular DICOM header field that causes Slicer to load images in the Head --> Foot orientation? If not, do loadables or volume contain any information that will be helpful?
So far, I tried looking at the IJKToRAS matrix of volume as well as the Slice Location header field of the DICOMs that were loaded into volume, but neither of those 2 options seem to help me identify when volume has the orientation that I don’t want.

Thanks,
Rohan Nadkarni

Axis order depends on how the image was acquired, but the exact mapping normally does not matter, as all image processing is be done in physical space anyway.

Head->Foot direction = Superior->Inferior direction = -S axis direction. Direction of S axis in IJK coordinate system is defined in the third column of the RASToIJK matrix.

1 Like