Child pages
  • DICOM Loaded in wrong order / slice spacing incorrect
Skip to end of metadata
Go to start of metadata


The problem occurs with a number of the datasets, but we particularly noticed it with Soft-tissue-Sarcoma in the dicoms in


Basically if you read the dicoms using SimpleITK.ReadImage or VTK the tool loads the files in the same order your list is in (usually alphabetical order). The mapping between the slices and the files are not in alphabetical order and are instead in a random order. This causes the Slice Spacing (a tag that is missing in these data) to be computed incorrectly since it is the difference in position between file 0 and 1. It also causes brain slices to turn up between two lung slices and other strange artifacts.


The files (or just their headers) need to be read in individually first and the Slice Location or GetOrigin() extracted. This information can then be taken in order to sort the files correctly.

For SimpleITK in Python this can be done with the following code

# noinspection PyPep8Naming
import SimpleITK as sitk
def safe_sitk_read(img_list, *args, **kwargs):
Since the default function just looks at images 0 and 1 to determine slice thickness
and the images are often not correctly alphabetically sorted, much slower
 :param img_list:
 pimg_list = [(sitk.ReadImage(x).GetOrigin(), x) for x in img_list]

s_img_list = [path for _, path in sorted(pimg_list, key = lambda x: x[0][2])] # sort by z
return sitk.ReadImage(s_img_list, *args, **kwargs)



With pydicom this can be done by sorting on the .SliceLocation field







Related articles