# DICOMOrient Voxel Data Permutations/Flips in SimpleITK

**URL:** https://discourse.itk.org/t/dicomorient-voxel-data-permutations-flips-in-simpleitk/7516
**Category:** Engineering
**Tags:** imageseries, orientation, dicom, simpleitk, python
**Created:** [May 9, 2025, 1:05pm UTC](https://discourse.itk.org/t/dicomorient-voxel-data-permutations-flips-in-simpleitk/7516 "2025-05-09T13:05:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ahulist](https://discourse.itk.org/user_avatar/discourse.itk.org/ahulist/32/4509_2.png) [@ahulist](https://discourse.itk.org/u/ahulist)
#### Post date: [May 9, 2025, 1:05pm UTC](https://discourse.itk.org/t/dicomorient-voxel-data-permutations-flips-in-simpleitk/7516/1 "2025-05-09T13:05:20Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 9, 2025, 1:50pm UTC](https://discourse.itk.org/t/dicomorient-voxel-data-permutations-flips-in-simpleitk/7516/2 "2025-05-09T13:50:23Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![ahulist](https://discourse.itk.org/user_avatar/discourse.itk.org/ahulist/32/4509_2.png) [@ahulist](https://discourse.itk.org/u/ahulist)
#### Post date: [May 12, 2025, 4:03am UTC](https://discourse.itk.org/t/dicomorient-voxel-data-permutations-flips-in-simpleitk/7516/3 "2025-05-12T04:03:52Z")

</div>

Oh, I was way overcomplicating things. Thank you!
