def loadTestData(self): #download data and add to dicom database zipFileUrl = 'http://slicer.kitware.com/midas3/download/item/257234/QIN-HEADNECK-01-0139-PET.zip' zipFilePath = self.tempDataDir + '/dicom.zip' zipFileData = self.tempDataDir + '/dicom' expectedNumOfFiles = 545 if not os.access(self.tempDataDir, os.F_OK): os.mkdir(self.tempDataDir) if not os.access(zipFileData, os.F_OK): os.mkdir(zipFileData) slicer.util.downloadAndExtractArchive(zipFileUrl, zipFilePath, zipFileData, expectedNumOfFiles) DICOMUtils.importDicom(zipFileData) # load dataset dicomFiles = slicer.util.getFilesInDirectory(zipFileData) loadablesByPlugin, loadEnabled = DICOMUtils.getLoadablesFromFileLists( [dicomFiles], ['DICOMScalarVolumePlugin']) loadedNodeIDs = DICOMUtils.loadLoadables(loadablesByPlugin) imageNode = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0]) imageNode.SetSpacing( 3.3940266832237, 3.3940266832237, 2.02490234375 ) # mimic spacing as produced by Slicer 4.10 for which the test was originally developed imageNode.SetOrigin( 285.367523193359375, 494.58682250976556816, -1873.3819580078125 ) # mimic origin as produced by Slicer 4.10 for which the test was originally developed # apply the SUVbw conversion factor and set units and quantity suvNormalizationFactor = 0.00040166400000000007 quantity = slicer.vtkCodedEntry() quantity.SetFromString( 'CodeValue:126400|CodingSchemeDesignator:DCM|CodeMeaning:Standardized Uptake Value' ) units = slicer.vtkCodedEntry() units.SetFromString( 'CodeValue:{SUVbw}g/ml|CodingSchemeDesignator:UCUM|CodeMeaning:Standardized Uptake Value body weight' ) multiplier = vtk.vtkImageMathematics() multiplier.SetOperationToMultiplyByK() multiplier.SetConstantK(suvNormalizationFactor) multiplier.SetInput1Data(imageNode.GetImageData()) multiplier.Update() imageNode.GetImageData().DeepCopy(multiplier.GetOutput()) imageNode.GetVolumeDisplayNode().SetWindowLevel(6, 3) imageNode.GetVolumeDisplayNode().SetAndObserveColorNodeID( 'vtkMRMLColorTableNodeInvertedGrey') imageNode.SetVoxelValueQuantity(quantity) imageNode.SetVoxelValueUnits(units) return imageNode
def loadTestData(self): self.patienName = 'UNIFORMITY^Bio-mCT' #download data and add to dicom database zipFileUrl = 'https://github.com/QIICR/SlicerPETPhantomAnalysis/releases/download/test-data/PETCylinderPhantom.zip' zipFilePath = self.tempDataDir + '/dicom.zip' zipFileData = self.tempDataDir + '/dicom' expectedNumOfFiles = 171 if not os.access(self.tempDataDir, os.F_OK): os.mkdir(self.tempDataDir) if not os.access(zipFileData, os.F_OK): # download DICOM test dataset os.mkdir(zipFileData) slicer.util.downloadAndExtractArchive(zipFileUrl, zipFilePath, zipFileData, expectedNumOfFiles) DICOMUtils.importDicom(zipFileData) # load dataset dicomFiles = slicer.util.getFilesInDirectory(zipFileData) loadablesByPlugin, loadEnabled = DICOMUtils.getLoadablesFromFileLists( [dicomFiles], ['DICOMScalarVolumePlugin']) loadedNodeIDs = DICOMUtils.loadLoadables(loadablesByPlugin) imageNode = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0]) # apply the SUVbw conversion factor and set units and quantity suvNormalizationFactor = 0.00012595161151 quantity = slicer.vtkCodedEntry() quantity.SetFromString( 'CodeValue:126400|CodingSchemeDesignator:DCM|CodeMeaning:Standardized Uptake Value' ) units = slicer.vtkCodedEntry() units.SetFromString( 'CodeValue:{SUVbw}g/ml|CodingSchemeDesignator:UCUM|CodeMeaning:Standardized Uptake Value body weight' ) multiplier = vtk.vtkImageMathematics() multiplier.SetOperationToMultiplyByK() multiplier.SetConstantK(suvNormalizationFactor) multiplier.SetInput1Data(imageNode.GetImageData()) multiplier.Update() imageNode.GetImageData().DeepCopy(multiplier.GetOutput()) imageNode.GetVolumeDisplayNode().SetWindowLevel(6, 3) imageNode.GetVolumeDisplayNode().SetAndObserveColorNodeID( 'vtkMRMLColorTableNodeInvertedGrey') imageNode.SetVoxelValueQuantity(quantity) imageNode.SetVoxelValueUnits(units) return imageNode
def accessDICOMwebStudy(self, request, requestBody): """ Access DICOMweb server to download requested study, add it to Slicer's dicom database, and load it into the scene. :param requestBody: is a json string :param requestBody['dicomWEBPrefix']: is the start of the url :param requestBody['dicomWEBStore']: is the middle of the url :param requestBody['studyUID']: is the end of the url :param requestBody['accessToken']: is the authorization bearer token for the DICOMweb server """ p = urllib.parse.urlparse(request.decode()) q = urllib.parse.parse_qs(p.query) request = json.loads(requestBody), b'application/json' dicomWebEndpoint = request['dicomWEBPrefix'] + '/' + request[ 'dicomWEBStore'] print(f"Loading from {dicomWebEndpoint}") from DICOMLib import DICOMUtils loadedUIDs = DICOMUtils.importFromDICOMWeb( dicomWebEndpoint=request['dicomWEBPrefix'] + '/' + request['dicomWEBStore'], studyInstanceUID=request['studyUID'], accessToken=request['accessToken']) files = [] for studyUID in loadedUIDs: for seriesUID in slicer.dicomDatabase.seriesForStudy(studyUID): for instance in slicer.dicomDatabase.instancesForSeries( seriesUID): files.append( slicer.dicomDatabase.fileForInstance(instance)) loadables = DICOMUtils.getLoadablesFromFileLists([files]) loadedNodes = DICOMUtils.loadLoadables(loadLoadables) print(f"Loaded {loadedUIDs}, and {loadedNodes}") return b'{"result": "ok"}'