How to read dicom files in two folders by SimpleITK?

SimpleITK is a useful tool for medical image processing.

It can read dicom images by:

import SimpleITK as sitk

series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(file_path)

series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(file_path, series_IDs[1])
...

However, the sitk.ImageSeriesReader.GetGDCMSeriesIDs need all dicom files are included in the file_path. But, what if the folder structure is:

file_path

  sery1
    img1.dcm
    img2.dcm
    ...
  sery2
    img1.dcm
    img2.dcm
  sery ...
  img1.dcm
  img2.dcm
  ...

How can I read the above file_path?

Hello @zhang-qiang-github,

Please take a look at the characterize_data.py script, specifically the inspect_series and inspect_single_series functions.

There are typically several series in a DICOM study, such as localizers, 3D volumes (often potentially repeated, with the same or slightly different imaging parameters), reconstructions with different parameters, secondary captures, structured reports, dose reports, etc.

You can certainly write a script that iterates through all the files of a study and guesses which ones you are interested in for a specific analysis, but I would suggest two other approaches that may be better and safer:

Option B. Use a DICOM viewer application to index the folder, get a list of what series are found there, load the potentially interesting ones for viewing. Once you decided which series you want to use, take note of the series instance UID or export them to a separate folder. You can use any interactive medical image viewer that has a DICOM indexer, but research applications, such as 3D Slicer or ITK-snap are better in exporting to research file formats (NRRD, NIFTI,… that ITK can very quickly and easily read).

Option C. You can run your study through dcm2niix, review the created nifti or nrrd files in an image viewer, and keep the files that are relevant.

2 Likes