# Import DICOM files from python interactor add extra volumes and nodes

**URL:** <https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087>\
**Category:** Development\
**Tags:** dicom\
**Created:** [August 5, 2021, 5:22pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087 "2021-08-05T17:22:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotsen](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hotsen](https://discourse.slicer.org/u/hotsen)\
**Post date:** [August 5, 2021, 5:22pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087/1 "2021-08-05T17:22:42Z")

</div>

Operating system: win10  
Slicer version: stable version 4.11.20210226  
Expected behavior: Manually loading works fine  
Actual behavior: python interactor add extra volumes and nodes

Hi all,

I am new to Slicer. I got 5 folders of DICOM files with one folder contains CT and other four folders contains MRI and DWI. All files ending with .dcm

If I load these folders using DCM module, everything works fine. But I need to develop a script to do this in the python Interactor. Here is what I found online:

```python
dicomDataDir = r"C:\MyDicomFoldercontainsFivefolders"
from DICOMLib import DICOMUtils
DICOMUtils.importDicom(dicomDataDir)
patientUIDs = slicer.dicomDatabase.patients()
for patientUID in patientUIDs:
    loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))   

```

This code will import all the data and some extra volumes named “Sequence” (just one slice of image) and some extra nodes with “browser” in the name. Checked the source code of DICOMUtils, really can’t figure out where went wrong.

![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/7/37e499f1e30c09d50fa470450f43b99685b6d3e5.png)  
 ![Capture1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/a/2ad8d0835cdd702e8ca5bbabba3749fbb4810334.png)

Any advice? Thanks.

Hotsen

---

<div class="post-metadata">

**Author:** ![hotsen](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hotsen](https://discourse.slicer.org/u/hotsen)\
**Post date:** [August 6, 2021, 3:06pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087/2 "2021-08-06T15:06:39Z")

</div>

Just an update. Not sure this is possible, I am thinking to call “Load” function (Load button) in DCM module using code. Now I can import the DICOM files into DICOMdatabase using the following code:

```python
dicomFilesDirectory = r"C:\MyDicomFoldercontainsFivefolders"
slicer.util.selectModule("DICOM")
dicomBrowser = slicer.modules.DICOMWidget.browserWidget.dicomBrowser
# use dicomBrowser.ImportDirectoryCopy to make a copy of the files (useful for importing data from removable storage)
dicomBrowser.importDirectory(dicomFilesDirectory, dicomBrowser.ImportDirectoryAddLink)
# wait for import to finish before proceeding (optional, if removed then import runs in the background)
dicomBrowser.waitForImportFinished()

```

After checking the source code of DICOMBrowser.py, I found that “Load” button is calling “loadCheckedLoadables” function, but I cannot call this function using “dicomBrowser.loadCheckedLoadables()”. Any suggestion on how to do that?

Thank you!

---

<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:** [August 7, 2021, 5:25pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087/3 "2021-08-07T17:25:35Z")

</div>

Thanks for reporting this. When using `loadSeriesByUID` from Python, the function loaded all possible interpretations of the series. It makes more sense to use only the highest-confidence loadable by default (as it is done when using the DICOM browser in the non-advanced mode). I’ve [changed the function](https://github.com/Slicer/Slicer/commit/b7f6be2b6d61bc4703d40fbe0243e16f7a790a3a) accordingly - the update will be available in Slicer Preview Releases from tomorrow.

---

<div class="post-metadata">

**Author:** ![hotsen](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hotsen](https://discourse.slicer.org/u/hotsen)\
**Post date:** [August 9, 2021, 7:52pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087/4 "2021-08-09T19:52:22Z")

</div>

Thank you, Andras. The Preview Release solved the problem!

---

<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:** [August 9, 2021, 11:20pm UTC](https://discourse.slicer.org/t/import-dicom-files-from-python-interactor-add-extra-volumes-and-nodes/19087/5 "2021-08-09T23:20:47Z")

</div>

A post was split to a new topic: [Radiomics error - No module named ‘pywt’](https://discourse.slicer.org/t/radiomics-error-no-module-named-pywt/19128)
