Load Dicom series file problems

Operating system:win7
Slicer version: 4.9
Expected behavior:
Actual behavior:

Hi, I had created the python script that load the series of the DICOM files. the script is follow:

def LoadDicomFile(path=None,NodeName=None):
filelist=os.listdir(path)
progress = slicer.util.createProgressDialog(parent=None, value=0, maximum=len(filelist))
plugin=DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
from DICOMLib import DICOMLoadable
loadable=DICOMLoadable()
step=0
for filename in filelist:
loadable.files.append(path + ‘/’ + filename)
labletext = ‘\n LoadDicomFile %s …’ % filename
progress.labelText = labletext
slicer.app.processEvents()
progress.setValue(step)
step += 1
slicer.app.processEvents()
try:
flag = plugin.load(loadable)
except:
print ‘except load false …’
progress.close()
del plugin
del loadable

LoadDicomFile(‘f:/data/’)
but the MPR seem is not good look this… the script have any problems???

%E6%97%A0%E6%A0%87%E9%A2%98

You get the file list by calling filelist=os.listdir(path), which returns the files in some random order (how they are ordered in the file system). See this topic about how to do it correctly:

Thanks for your quickly help, i will try the Load the ordered files…

Hi! I’m experimenting with controlling 3DSlicer from Jupyter Notebook and I found the initial script useful… I want to share the Python3 version of it since others may end up here:

import os
from glob import glob
from DICOMLib import DICOMLoadable
import DICOMScalarVolumePlugin

def load_dicom_folder(path):
    plugin = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
    loadable = DICOMLoadable()
    for file_path in sorted(glob(os.path.join(path, '*'))):
        loadable.files.append(file_path)
    try:
        flag = plugin.load(loadable)
    except Exception as e:
        print(e)

load_dicom_folder('folderPath')

I removed the progress dialog window, since it’s so fast It’s barely useful nowadays.

1 Like

You can also find up-to-date DICOM loading examples in the script repository.

1 Like

I did not find found that page before… the code there is much better
than mine, with the official script in the Wiki the Patient and the
Study are also handled! :slight_smile:

Thank you!

1 Like