# How are image stacks sorted?

**URL:** <https://discourse.orthanc-server.org/t/how-are-image-stacks-sorted/2913>\
**Category:** Google Groups archive\
**Created:** [May 16, 2022, 8:04pm UTC](https://discourse.orthanc-server.org/t/how-are-image-stacks-sorted/2913 "2022-05-16T20:04:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Sly](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@John\_Sly](https://discourse.orthanc-server.org/u/John_Sly)\
**Post date:** [May 16, 2022, 8:04pm UTC](https://discourse.orthanc-server.org/t/how-are-image-stacks-sorted/2913/1 "2022-05-16T20:04:37Z")

</div>

I’m currently using orthanc with the osimis viewer. (I can pull the docker info for the specific image if needed), and I had a question about how stacks are organized. I’ve had a few physicians complain that the images are out of order when they view a study. I’ll readily admit that I’m a programmer and I don’t work in a cath lab. We are also collecting images from multiple cath labs and locations, so I think there is room for a wide variety of varience.

I wanted to see if there’s anything I can do to make sure images are ordered properly or if there’s anything I can pass along to the cath lab techs to make sure that the images are ordered correctly.

Any help or further info you can pass along would be hugely appreciated!!

---

<div class="post-metadata">

**Author:** ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)\
**Post date:** [May 17, 2022, 8:10am UTC](https://discourse.orthanc-server.org/t/how-are-image-stacks-sorted/2913/2 "2022-05-17T08:10:50Z")

</div>

Hi John,

Here’s the code that handles slices sorting:  
[https://bitbucket.org/osimis/osimis-webviewer-plugin/src/417247b97410bb9376035edf3067c2971e63f460/backend/WebViewerLibrary/Series/SeriesHelpers.cpp#lines-358](https://bitbucket.org/osimis/osimis-webviewer-plugin/src/417247b97410bb9376035edf3067c2971e63f460/backend/WebViewerLibrary/Series/SeriesHelpers.cpp#lines-358)

It first tries to sort according to ImagePositionPatient and, if not possible, sort according to InstanceNumber or ImageIndex.  
Note that, in order to sort according to ImagePositionPatient, the ImageOrientationPatient tag must be set correctly as well.

HTH

Alain.
