def TestPythonFilter(filename, verbose=False): r = gdcm.Reader() r.SetFileName(filename) sucess = r.Read() if (not sucess): return 1 file = r.GetFile() ds = file.GetDataSet() # Change gdcm struct into something swig can digest: pds = gdcm.PythonDataSet(ds) sf = gdcm.PythonFilter() pds.Start() # Make iterator go at begining dic1 = {} dic2 = {} sf.SetFile(file) # extremely important while (not pds.IsAtEnd()): t = str(pds.GetCurrent().GetTag()) print t res = sf.ToPyObject(pds.GetCurrent().GetTag()) dic2[t] = res[1] dic1[res[0]] = res[1] pds.Next() #print dic1 #print dic2 try: print "Pixel Representation=", dic2['(0028,0103)'] except KeyError: print "Tag not found in dataset" return 0
def get_python_filter(self): f = gdcm.PythonFilter() f.SetFile(self.dicom_file) return f
@author: Ryan """ # This script is an example of using GDCM to provide the appropriate data type import gdcm f = 'E:\\images\\pacs_testing\\folders\\CR_IMS2\\0405296098\\0\\im_1\\i0000,0000b.dcm' r = gdcm.Reader() r.SetFileName(f) if not r.Read(): raise NotADirectoryError(f) f = gdcm.PythonFilter() f.SetFile(r.GetFile()) t = gdcm.Tag(0x0018, 0x0060) ds = r.GetFile().GetDataSet() # The code contained in the print statement causes the kernel to die... #print(f.ToPyObject(t)) # The following code attempts to discover ever DICOM meta data element tag = [] for i in range(1, 65535): for j in range(1, 65535): t = gdcm.Tag(i, j) if ds.FindDataElement(t): tag.append((hex(i), hex(j)))