def _loadWithPlugin(self, UID, pluginName): dicomWidget = slicer.modules.dicom.widgetRepresentation().self() dicomPluginCheckbox = dicomWidget.detailsPopup.pluginSelector.checkBoxByPlugin dicomPluginStates = {(key,value.checked) for key,value in dicomPluginCheckbox.iteritems()} for cb in dicomPluginCheckbox.itervalues(): cb.checked=False dicomPluginCheckbox[pluginName].checked = True success=DICOMUtils.loadSeriesByUID([UID]) for key,value in dicomPluginStates: dicomPluginCheckbox[key].checked=value
def getImageFromDICOMInformation(self, dcmInfo): loadedNodeIDs = [] with DICOMUtils.TemporaryDICOMDatabase() as database: DICOMUtils.importDicom(os.path.join(self.path, 'DICOM'), database) series = SlicerDICOMDatabase().geSeriestMatchingDescriptionAndDateTime(dcmInfo['SeriesDescription'], dcmInfo['AcquisitionDateTime']) loadedNodeIDs.extend(DICOMUtils.loadSeriesByUID([series])) for nodeID in loadedNodeIDs[::-1]: volumeNode = slicer.util.getNode(nodeID) if re.search('.*' + dcmInfo['SeriesDescription'] + '.*', volumeNode.GetName()): return volumeNode raise RuntimeError('Unable to find image in DICOM: ' + self.path)
def _loadTestData_WithPETDICOMExtension(self): """ load SUV normalized PET scan from DICOM fileassuming Slicer-PETDICOM extension is installed and enabled """ from DICOMLib import DICOMUtils import urllib data = { 'PETVolume': { 'UID': '1.3.6.1.4.1.14519.5.2.1.2744.7002.886851941687931416391879144903', 'url': 'http://slicer.kitware.com/midas3/download/item/257234/QIN-HEADNECK-01-0139-PET.zip', 'zipFile': 'QIN-HEADNECK-01-0139-PET.zip', 'SUVNormalizationFactor': 0.00040166400000000007 } } destinationDirectory = self.tempDataDir for key, value in data.iteritems(): # download data if necessary UID = value['UID'] if not len(slicer.dicomDatabase.filesForSeries(UID)): url = value['url'] zipFile = value['zipFile'] filePath = os.path.join(destinationDirectory, zipFile) if not os.path.exists(os.path.dirname(filePath)): os.makedirs(os.path.dirname(filePath)) logging.debug('Saving download %s to %s ' % (url, filePath)) if not os.path.exists(filePath) or os.stat(filePath).st_size == 0: slicer.util.delayDisplay('Requesting download of %s...\n' % url, 1000) urllib.urlretrieve(url, filePath) if os.path.exists(filePath) and os.path.splitext(filePath)[1]=='.zip': success = slicer.app.applicationLogic().Unzip(filePath, destinationDirectory) if not success: logging.error("Archive %s was NOT unzipped successfully." % filePath) indexer = ctk.ctkDICOMIndexer() indexer.addDirectory(slicer.dicomDatabase, destinationDirectory, None) indexer.waitForImportFinished() # load dataset success=DICOMUtils.loadSeriesByUID([data['PETVolume']['UID']]) if not success: logging.error("Unable to load dicom data %s\n." % data['PETVolume']['UID']) return slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLScalarVolumeNode')