Sfoglia il codice sorgente

Adding misc dicom tags and isDicom query

Andrej Studen 5 anni fa
parent
commit
0df12f84c4
1 ha cambiato i file con 31 aggiunte e 6 eliminazioni
  1. 31 6
      labkeySlicerPythonExtension/loadDicom.py

+ 31 - 6
labkeySlicerPythonExtension/loadDicom.py

@@ -14,7 +14,7 @@ class loadDicom(slicer.ScriptedLoadableModule.ScriptedLoadableModule):
         slicer.ScriptedLoadableModule.ScriptedLoadableModule.__init__(self, parent)
         self.className="loadDicom"
         self.parent.title="loadDicom"
-        self.parent.categories = ["Examples"]
+        self.parent.categories = ["LabKey"]
         self.parent.dependencies = []
         self.parent.contributors = ["Andrej Studen (UL/FMF)"] # replace with "Firstname Lastname (Organization)"
         self.parent.helpText = """
@@ -44,8 +44,10 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
               'modality': {'tag':"0008,0060",'VR':'CS'},
               'presentationIntentType': {'tag':"0008,0068",'VR':'CS'},
               'manufacturer': {'tag':"0008,0070",'VR':'LO'},
+              'institutionName': {'tag':"0008,0080",'VR':'LO'},
               'studyDescription': {'tag':"0008,1030",'VR':'LO'},
               'seriesDescription': {'tag':"0008,103e",'VR':'LO'},
+              'manufacturerModelName': {'tag':"0008,1090",'VR':'LO'},
               'patientName': {'tag':"0010,0010",'VR':'PN'},
               'patientId': {'tag':"0010,0020",'VR':'LO'},
               'patientBirthDate': {'tag':"0010,0030",'VR':'DA'},
@@ -70,7 +72,8 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
               'frameOfReferenceInstanceUid': {'tag':"0020,0052",'VR':'UI'},
               'imageLaterality': {'tag':"0020,0062",'VR':'CS'},
               'imagesInAcquisition': {'tag':"0020,1002",'VR':'IS'},
-              'photometricInterpretation': {'tag':"0028,0004",'VR':'CS'}
+              'photometricInterpretation': {'tag':"0028,0004",'VR':'CS'},
+              'reconstructionMethod': {'tag':"0054,1103",'VR':'LO'}
       }
       self.tagPyDicom={
               'studyDate': 0x00080020,
@@ -163,7 +166,7 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
     def applyFilter(self,loadable,filter,nodeMetadata):
 
         filterOK=True
-
+        print("Opening {}").format(loadable.files[0]);
         fileBuffer = open(loadable.files[0])
         try:
             plan = dicom.read_file(fileBuffer)
@@ -293,18 +296,40 @@ class loadDicomLogic(slicer.ScriptedLoadableModule.ScriptedLoadableModuleLogic):
 
         return segmentationNodes
 
+def isDicom(file):
+    try:
+        f=open(file,'rb')
+    except IOError:
+        return False
+
+    f.read(128)
+    dt=f.read(4)
+    f.close()
+    return dt=='DICM'
+
+
 def dicomValue(file,tag):
     dcmdump=os.path.join(os.environ['SLICER_HOME'],"bin")
     dcmdump=os.path.join(dcmdump,"dcmdump")
     try:
-        out=subprocess.check_output([dcmdump,'+P',tag,file])
-        out=re.sub(r'^.*\[(.*)\].*\n$',r'\1',out)
+        out=subprocess.check_output([dcmdump,'+p','+P',tag,file])
+        print("Tag {} Line '{}'").format(tag,out)
+        if len(out)==0:
+            return out
+        tag1="^\({}\)".format(tag)
+        lst=out.split('\n')
+        rpl=[re.sub(r'^.*\[(.*)\].*$',r'\1',f) for f in lst]
+        mtch=[re.match(tag1,f) for f in lst]
+        out=[x for y,x in zip(mtch,rpl) if not y==None]
+        out=out[0]
+        #out=re.sub(r'^.*\[(.*)\].*\n$',r'\1',out)
         #separate out series
+        print("Tag {} Parsed value {}").format(tag,out)
         if out.find('\\')>-1:
             out=out.split('\\')
 
         return out
-    except:
+    except subprocess.CalledProcessError as e:
         return None
 
 def clearNodes():