# ITK Image Direction vs DICOM Image Orientation (Patient)

**URL:** https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [December 17, 2023, 8:22pm UTC](https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364 "2023-12-17T20:22:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![aditya](https://discourse.itk.org/user_avatar/discourse.itk.org/aditya/32/3808_2.png) [@aditya](https://discourse.itk.org/u/aditya)
#### Post date: [December 17, 2023, 8:22pm UTC](https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364/1 "2023-12-17T20:22:29Z")

</div>

I am working with a directory containing sagittal DICOM images.

Here is how I obtain Image Orientation (DICOM tag 0020,0037) using pydicom.

```auto
from pydicom import dcmread
import os
dcm_dir = r"path/to/dicom/dir/sagittal_acq"
ds = dcmread(os.path.join(dcm_dir,"000000.dcm"))
ds.ImageOrientationPatient
Out[88]: [0, 1, -1e-016, 0.05582152223083, 0, -0.9984407632183]

```

In the following code, I read the contents of this directory into an ITK Image and get the Direction. However, the Direction differs from original DICOM (0020,0037).

```auto
import SimpleITK as sitk
reader = sitk.ImageSeriesReader() 
dicom_names = reader.GetGDCMSeriesFileNames(dcm_dir) 
reader.SetFileNames(dicom_names) 
image_from_dcm = reader.Execute() 
sitk.DICOMOrientImageFilter_GetOrientationFromDirectionCosines(image_from_dcm.GetDirection())
Out[92]: 'PIR'
image_from_dcm.GetDirection()
Out[91]: 
(-5.573448326015114e-18,
 0.055821522230826974,
 -0.9984407632182459,
 1.0,
 -4.81482486096809e-35,
 -5.582152223082697e-18,
 -3.1160423441667093e-19,
 -0.9984407632182459,
 -0.055821522230826974)

```

Is there a way to get Direction from ITK Image that matches DICOM Orientation 0020,0037?

As Image row is oriented from A to P (as shown by DICOMOrientImageFilter\_GetOrientationFromDirectionCosines), I expected the direction cosines of row (1st three elements) from ITK’s GetDirection to be [0,1,0], which is what I get with ds.ImageOrientationPatient[:3].

I tested the same with HFS and FFS oriented DICOM files and the Direction obtained from getDirection() matches DICOM.

For example, for FFS scan I get the following which matches DICOM Orientation 0020,0037

```auto
img_ori = image_from_dcm.GetDirection()
img_ori
Out[8]: (-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0)
sitk.DICOMOrientImageFilter_GetOrientationFromDirectionCosines(img_ori)
Out[9]: 'RPI'

```

Thanks!

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [December 18, 2023, 1:19am UTC](https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364/2 "2023-12-18T01:19:59Z")

</div>

Hello @aditya,

The DICOM tag 0020,0037 “Image Orientation Patient” lists the x axis, first three numbers, followed by the y axis, last three numbers. These are the columns of the direction cosine matrix (see [the standard](https://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.2.1.1)). These correspond to the first two columns of the direction matrix returned by the `GetDirection` method, which returns the matrix in row major order (first three numbers are first row…). If you look at that matrix you will see that the first column is `[0, 1.0, 0]` and the second column is `[0.055821522230826974, 0, -0.9984407632182459]` which match the values in the DICOM tag.

---

<div class="post-metadata">

### Author: ![aditya](https://discourse.itk.org/user_avatar/discourse.itk.org/aditya/32/3808_2.png) [@aditya](https://discourse.itk.org/u/aditya)
#### Post date: [December 18, 2023, 3:08am UTC](https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364/3 "2023-12-18T03:08:37Z")

</div>

Got it. Thank you so much @zivy

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [April 9, 2024, 7:47am UTC](https://discourse.itk.org/t/itk-image-direction-vs-dicom-image-orientation-patient/6364/4 "2024-04-09T07:47:25Z")

</div>

hi, I used getDirection method to get the returned direction was  
 ![Snipaste_2024-04-09_15-42-06](https://discourse.itk.org/uploads/default/original/2X/3/3c9f1d3c23af32235dfcd0a437bf15ee127cb284.jpeg)

but the dicom orientation tag was  
 ![Snipaste_2024-04-09_15-43-58](https://discourse.itk.org/uploads/default/original/2X/d/da3542654128bfdb56334f855624629aabb5b80d.jpeg)

it seems the direction maxtrix first colums was [1,0,0], why didn’t the orientation correspond to the first two columns of the direction matrix?
