# GetGDCMSeriesFileNames: ordering of the returned files

**URL:** https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369
**Category:** Engineering
**Tags:** python
**Created:** [August 26, 2021, 7:18am UTC](https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369 "2021-08-26T07:18:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![KrisHan999](https://discourse.itk.org/user_avatar/discourse.itk.org/krishan999/32/2239_2.png) [@KrisHan999](https://discourse.itk.org/u/KrisHan999)
#### Post date: [August 26, 2021, 7:18am UTC](https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369/1 "2021-08-26T07:18:06Z")

</div>

Same as the title, I had a CT series, after running the ‘GetGDCMSeriesFileNames’, the files were returned according to the file name, instead of the z coordinates. I just wonder, how the files are ordered in function ‘GetGDCMSeriesFileNames’? It would be better to show me the source code or any samples.

---

<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: [August 26, 2021, 1:04pm UTC](https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369/2 "2021-08-26T13:04:48Z")

</div>

Hello @KrisHan999,

The files are returned in order according to the z coordinate obtained from the Image Position (Patient), 0020|0032, DICOM tag. The code itself is deep in the bowls of the toolkits (SimpleITK-\>ITK-\>[GDCM code](https://github.com/malaterre/GDCM/blob/e501d71938a0889f55885e4401fbfe60a8b7c4bd/Source/MediaStorageAndFileFormat/gdcmSerieHelper.cxx#L308)).

Please check the files’ DICOM tag values and see if they are what you expect them to be.

---

<div class="post-metadata">

### Author: ![KrisHan999](https://discourse.itk.org/user_avatar/discourse.itk.org/krishan999/32/2239_2.png) [@KrisHan999](https://discourse.itk.org/u/KrisHan999)
#### Post date: [August 26, 2021, 6:03pm UTC](https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369/3 "2021-08-26T18:03:27Z")

</div>

Thanks for your response. However, I installed the newest version of the python package, but the results are not exactly as you said. Please check the 2 CT series as in [https://drive.google.com/file/d/1Zex3h9hfubG9zAUYsYBG2T758V5xzaHU/view?usp=sharing](https://drive.google.com/file/d/1Zex3h9hfubG9zAUYsYBG2T758V5xzaHU/view?usp=sharing). The two cases in the line, one is in ascending order, the other is in descending order of z coordinates. I think whether the ordering is determined by the PatientPosition, ‘Head-First’ or ‘Feet-First’.

What’s more, for the GetDirection() function, how the direction for z-axis is determined?

Thanks again.

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [August 26, 2021, 11:49pm UTC](https://discourse.itk.org/t/getgdcmseriesfilenames-ordering-of-the-returned-files/4369/4 "2021-08-26T23:49:43Z")

</div>

Slices are sorted by _Image Position (Patient)_ along the slice normal. For series named “Couch-replaced CT Series” _Image Orientation (Patient)_ is `-1\0\0\0\1\0`, the (seldom) orientation is

```cpp
-1 0 0
 0 1 0
 0 0 -1

```

X: from left to right  
Y: from anterior to posterior  
Z: from superior to inferior

Another series has _Image Orientation (Patient)_ `1\0\0\0\1\0`, identity  
X: from right to left  
Y: from anterior to posterior  
Z: from inferior to superior

> how the direction for z-axis is determined

Z-axis is right-handed cross product of “X” and “Y” defined in _Image Orientation (Patient)_.

_Patient Position_ (0018,5100) specifies the position of the patient relative to the imaging equipment space for annotation purposes only. It is not used at all in particular case.

**Edit** : for clarity, even if the orientation (RAI-code: LAS) is unusual, there are no problems with the volume, axis are correct.

 ![sl](https://discourse.itk.org/uploads/default/original/2X/3/3a0eab6fa878880f065b8d761e70111eb72c2fff.png)

 ![snap](https://discourse.itk.org/uploads/default/original/2X/2/2008492f275f05df7fd8d52bdefbb860fa6f9bf4.png)

 ![20210827-024004](https://discourse.itk.org/uploads/default/original/2X/9/9a1d2961c7cecd9b3bcc5f2aa3e3c43f2ca2ccd6.png)

**Edit** : another illustration (with images from ITK-Snap)

![las](https://discourse.itk.org/uploads/default/original/2X/e/efe826323c120781b5338bca2c0c7ac3be40373a.png)
