I am working with a directory containing sagittal DICOM images.
Here is how I obtain Image Orientation (DICOM tag 0020,0037) using pydicom.
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).
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
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!