Last active
August 29, 2015 14:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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