GDCM 3.2.1

WriteBuffer.py
1
14
15"""
16 Usage:
17
18 http://chuckhahm.com/Ischem/Zurich/XX_0134
19
20(2005,1132) SQ (Sequence with undefined length #=8) # u/l, 1 Unknown Tag & Data
21 (fffe,e000) na (Item with undefined length #=9) # u/l, 1 Item
22 (2005,0011) LO [Philips MR Imaging DD 002] # 26, 1 PrivateCreator
23 (2005,1137) PN [PDF_CONTROL_GEN_PARS] # 20, 1 Unknown Tag & Data
24 (2005,1138) PN (no value available) # 0, 0 Unknown Tag & Data
25 (2005,1139) PN [IEEE_PDF] # 8, 1 Unknown Tag & Data
26 (2005,1140) PN (no value available) # 0, 0 Unknown Tag & Data
27 (2005,1141) PN (no value available) # 0, 0 Unknown Tag & Data
28 (2005,1143) SL 3103 # 4, 1 Unknown Tag & Data
29 (2005,1144) OW 0566\0000\013b\0000\0a4a\0000\000e\0000\0a7a\0000\0195\0000\0008... # 3104, 1 Unknown Tag & Data
30 (2005,1147) CS [Y] # 2, 1 Unknown Tag & Data
31 (fffe,e00d) na (ItemDelimitationItem) # 0, 0 ItemDelimitationItem
32 (fffe,e000) na (Item with undefined length #=9) # u/l, 1 Item
33 (2005,0011) LO [Philips MR Imaging DD 002] # 26, 1 PrivateCreator
34 (2005,1137) PN [PDF_CONTROL_PREP_PARS] # 22, 1 Unknown Tag & Data
35 (2005,1138) PN (no value available) # 0, 0 Unknown Tag & Data
36 (2005,1139) PN [IEEE_PDF] # 8, 1 Unknown Tag & Data
37 (2005,1140) PN (no value available) # 0, 0 Unknown Tag & Data
38 (2005,1141) PN (no value available) # 0, 0 Unknown Tag & Data
39 (2005,1143) SL 7934 # 4, 1 Unknown Tag & Data
40 (2005,1144) OW 19b6\0000\005f\0000\1b2a\0000\00f3\0000\1eee\0000\0000\0000\0008... # 7934, 1 Unknown Tag & Data
41 (2005,1147) CS [Y] # 2, 1 Unknown Tag & Data
42 (fffe,e00d) na (ItemDelimitationItem) # 0, 0 ItemDelimitationItem
43...
44"""
45
46 import sys
47 import gdcm
48
49 if __name__ == "__main__":
50
51 file1 = sys.argv[1]
52 file2 = sys.argv[2]
53
54 r = gdcm.Reader()
55 r.SetFileName( file1 )
56 if not r.Read():
57 sys.exit(1)
58
59 fg = gdcm.FilenameGenerator()
60 f = r.GetFile()
61 ds = f.GetDataSet()
62 tsis = gdcm.Tag(0x2005,0x1132) #
63 if ds.FindDataElement( tsis ):
64 sis = ds.GetDataElement( tsis )
65 #sqsis = sis.GetSequenceOfItems()
66 # GetValueAsSQ handle more cases
67 sqsis = sis.GetValueAsSQ()
68 if sqsis.GetNumberOfItems():
69 nitems = sqsis.GetNumberOfItems();
70 fg.SetNumberOfFilenames( nitems )
71 fg.SetPrefix( file2 )
72 if not fg.Generate():
73 print "problem"
74 sys.exit(1)
75 for i in range(0,nitems):
76 item1 = sqsis.GetItem(i+1) # Item start at 1
77 nestedds = item1.GetNestedDataSet()
78 tprcs = gdcm.Tag(0x2005,0x1144) #
79 if nestedds.FindDataElement( tprcs ):
80 prcs = nestedds.GetDataElement( tprcs )
81 bv = prcs.GetByteValue()
82 print bv
83 f = open( fg.GetFilename(i) , "w" )
84 f.write( bv.WriteBuffer() )
gdcm::FilenameGenerator
FilenameGenerator.
Definition gdcmFilenameGenerator.h:37
gdcm::Reader
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39