Example #1
0
def TestStringFilter(filename, verbose=False):
    r = gdcm.Reader()
    r.SetFileName(filename)
    success = r.Read()
    if (not success): return 1

    file = r.GetFile()
    ds = file.GetDataSet()
    # Change gdcm struct into something swig can digest:
    pds = gdcm.PythonDataSet(ds)
    sf = gdcm.StringFilter()
    pds.Start()  # Make iterator go at beginning
    dic1 = {}
    dic2 = {}
    sf.SetFile(file)  # extremely important
    while (not pds.IsAtEnd()):
        t = str(pds.GetCurrent().GetTag())
        res = sf.ToStringPair(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
Example #2
0
    def _read_all_tags(self, filename):
        r = gdcm.Reader(filename)
        r.Read()
        f = r.GetFile()
        ds = file.GetDataSet()
        pds = gdcm.PythonDataSet(ds)
        sf = gdcm.StringFilter()
        pds.Start()  # Make iterator go at begining
        dic = {}
        sf.SetFile(f)  # extremely important
        while (not pds.IsAtEnd()):
            res = sf.ToStringPair(pds.GetCurrent().GetTag())
            dic[res[0]] = res[1]
            pds.Next()

        return dic