Child pages
  • DICOM Loaded in wrong order / slice spacing incorrect

Problem

The problem occurs with a number of the datasets, but we particularly noticed it with A radiomics model from joint FDG-PET and MRI texture features for the prediction of lung metastases in soft-tissue sarcomas of the extremities (Soft-tissue-Sarcoma) in the dicoms in

STS_004/1.3.6.1.4.1.14519.5.2.1.5168.1900.124239320067253523699285035604/1.3.6.1.4.1.14519.5.2.1.5168.1900.952127023780097934747932279670

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.

Solution

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:
 :return:
"""
 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

http://www.vtk.org/doc/nightly/html/classvtkDICOMImageReader.html

 

 

 

 

 

 

Related articles