DICOMOrient Voxel Data Permutations/Flips in SimpleITK

Hi all,

I’m working with a DICOM processing pipeline where I use sitk.DICOMOrient(image, "LPS") to reorient an original series. Later, I need to revert this lps_oriented_image back to match the exact voxel data order and geometric metadata (Origin, Spacing, Direction, Size) of the original image, assuming no resampling occurred during DICOMOrient.

Simply applying lps_oriented_image.CopyInformation(original_image) isn’t enough if DICOMOrient permuted data axes, as CopyInformation doesn’t change pixel data order or image size, leading to mismatches.

My core challenge is to reliably determine and apply the inverse data axis permutations and flips that DICOMOrient performed. I’ve tried inferring this from the direction cosine matrices, but it’s proven tricky and I couldn’t make it work.

Is there a recommended or canonical method in SimpleITK to:

  1. Either directly obtain the inverse data permutation/flip operations applied by DICOMOrient?
  2. Or, robustly calculate these inverse operations based on the original and LPS-oriented image’s metadata to perfectly restore the original voxel data layout?

The goal is for the “reverted” image to be identical to the original, not just geometrically equivalent for viewing, but also in its underlying voxel array structure and content (ideally having original and “reverted” series indistinguishable in a dicom viewer).

Any general strategies or insights would be greatly appreciated.

Thanks!

1 Like

You should save the original orientation string from the original image.
Something like:

img = sitk.Image(10,10,10,sitk.sitkFloat32)
original_orientation = sitk.DICOMOrientImageFilter.GetOrientationFromDirectionCosines(img.GetDirection())
img2 = sitk.DICOMOrient(img, "RPS")
restored_img = sitk.DICOMOrient(img2, original_orientation)

Then that original orientation can be applied with DICOMOrient, to revert.

EDIT: Updated to a complete example.

1 Like

Oh, I was way overcomplicating things. Thank you!