Skip to content

Instantly share code, notes, and snippets.

@mehrtash
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehrtash/cd4a43a3ab355898a05b to your computer and use it in GitHub Desktop.
Save mehrtash/cd4a43a3ab355898a05b to your computer and use it in GitHub Desktop.
Script to read multivolume images from Slicer DICOM database and save them as nrrd
directory = '.'
patientFolders = os.listdir(directory)
studyFolders = []
db = slicer.dicomDatabase
for index,patientFolder in enumerate(patientFolders):
fullPath = os.path.join(directory,patientFolder)
studyFolder = os.listdir(str(fullPath))[0]
fullPathStudyFolder = os.path.join(fullPath,studyFolder)
studyFolders.append(fullPathStudyFolder)
for i,studyFolder in enumerate(studyFolders):
seriesFolders = os.listdir(studyFolder)
for seriesFolder in seriesFolders:
fileNames = os.listdir(os.path.join(studyFolder,seriesFolder))
for index,fileName in enumerate(fileNames):
fileNames[index] = os.path.join(directory, studyFolder , seriesFolder,fileName)
plugin = slicer.modules.dicomPlugins['MultiVolumeImporterPlugin']()
print '-------------------------------------------'
if plugin:
loadables = plugin.examine([fileNames])
if len(loadables) == 0:
print('plugin failed to interpret this series')
else:
patientID = db.fileValue(loadables[0].files[0],'0010,0020')
seriesDescription = db.fileValue(loadables[0].files[0],'0008,103e')
outputPath = "~/temp/"+ patientID + ' '+seriesDescription + ".nrrd"
print outputPath
volume = plugin.load(loadables[0])
slicer.util.saveNode(volume,outputPath)
slicer.mrmlScene.RemoveNode(volume)
slicer.app.processEvents()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment