# Load DICOM series using python

**URL:** <https://discourse.slicer.org/t/load-dicom-series-using-python/3257>\
**Category:** Support\
**Tags:** dicom, python\
**Created:** [June 21, 2018, 1:33pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257 "2018-06-21T13:33:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_George](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ben_george/32/2992_2.png) [@Ben\_George](https://discourse.slicer.org/u/Ben_George)\
**Post date:** [June 21, 2018, 1:33pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/1 "2018-06-21T13:33:16Z")

</div>

Hi

I am trying to create a python script that can import a DICOM image series from a folder, however I can’t seem to find a way to make this work.

I can load a single DICOM file (in my case an RTSTRUCT) using this code:

```
contour_fn = 'contours.dcm'
	
	# Add filename to list for DICOM-RT module
	contour_vtkFileList = vtk.vtkStringArray()
	contour_vtkFileList.InsertNextValue(slicer.util.toVTKString(contour_fn))
	
	# Examine files
	contour_loadablesCollection = vtk.vtkCollection()
	slicer.modules.dicomrtimportexport.logic().ExamineForLoad(contour_vtkFileList, contour_loadablesCollection)
	# Set name for when loaded
	contour_loadablesCollection.GetItemAsObject(0).SetName('RTSTRUCT')
	
	# Load file
	contour_success = slicer.modules.dicomrtimportexport.logic().LoadDicomRT(contour_loadablesCollection.GetItemAsObject(0))

```

However, if I create a list of filenames to load, it doesn’t seem to work correctly. Specifically, my ‘loadablesCollection’ is empty.

Is there a way to do this? I have seen options for loading patients from the DICOM browser, but I don’t want to have to import all the data through that if possible. Also, I’m not sure what the patient name will be, so don’t know how I would do a load by name/ID.

Many thanks

Ben

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [June 21, 2018, 4:00pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/2 "2018-06-21T16:00:44Z")

</div>

Hi Ben,

There are many convenience functions just for this in DICOMUtils. So you don’t need to go through the logic classes:

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py>

I see you want to load RT data. The code form this automated test might help:

> <https://github.com/SlicerRt/SlicerRT/blob/master/DicomRtImportExport/Testing/Python/DicomRtImportTest.py>

  
or this  

> <https://github.com/SlicerRt/SlicerRT/blob/master/Testing/Python/IGRTWorkflow_SelfTest.py>

---

<div class="post-metadata">

**Author:** ![Ben\_George](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ben_george/32/2992_2.png) [@Ben\_George](https://discourse.slicer.org/u/Ben_George)\
**Post date:** [June 22, 2018, 6:49am UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/3 "2018-06-22T06:49:50Z")

</div>

Hi Csaba

Thanks for your response, I’ll take a look through the examples you suggested.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [July 30, 2018, 1:43pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/4 "2018-07-30T13:43:54Z")

</div>

You can also take a look at [this python module](https://github.com/SlicerProstate/mpReview/blob/master/mpReviewPreprocessor.py) that provides a command line tool to essentially take a folder with DICOM data, and organize it into patient/study/series hierarchy of folders accompanied by volumetric reconstructions for each series. It does not handle RT, but it should be easy to add that. You can also find more details here: [How can I convert DICOM series to NRRD files in batch mode?](https://discourse.slicer.org/t/how-can-i-convert-dicom-series-to-nrrd-files-in-batch-mode/3421).

---

<div class="post-metadata">

**Author:** ![zgk110](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zgk110](https://discourse.slicer.org/u/zgk110)\
**Post date:** [September 16, 2018, 3:40am UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/6 "2018-09-16T03:40:00Z")

</div>

Hi, i am trying to import a dicom series directory by python scripting, i just found the command 'slicer.util.loadNodeFromFile /loadScene/loadVolume ’ , is there any other function to load the dicom series from directory ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2018, 1:36pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/7 "2018-09-16T13:36:10Z")

</div>

The post above has been moved here, as the same question has been discussed in this topic. If you have any follow-up questions please post them here.

---

<div class="post-metadata">

**Author:** ![Markba122](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/markba122/32/79959_2.png) [@Markba122](https://discourse.slicer.org/u/Markba122)\
**Post date:** [April 10, 2025, 3:05pm UTC](https://discourse.slicer.org/t/load-dicom-series-using-python/3257/8 "2025-04-10T15:05:36Z")

</div>

Hi all,

Something that I hope could help is a Python class meant to quickly iterate down a series of folders with the help of SimpleITK to identifying unique images by their Series Instance UIDs. The found images can then be saved as SimpleITK Image files (‘.nii’) or NumPy arrays.

The GitHub repo has a Jupyter notebook to show you examples: [GitHub - brianmanderson/Dicom\_RT\_and\_Images\_to\_Mask: Tools to help with the conversion of DICOM images, RT Structures, and dose to useful Python objects. Essentially DICOM to NumPy and SimpleITK Images](https://github.com/brianmanderson/Dicom_RT_and_Images_to_Mask)

The publication that goes along with the program is also here: [Simple Python Module for Conversions between DICOM Images and Radiation Therapy Structures, Masks, and Prediction Arrays - PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC8102371/)

Hope this can help!  
Brian
