GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

NewSequence.py
1 ############################################################################
2 #
3 # Program: GDCM (Grassroots DICOM). A DICOM library
4 #
5 # Copyright (c) 2006-2011 Mathieu Malaterre
6 # All rights reserved.
7 # See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 #
9 # This software is distributed WITHOUT ANY WARRANTY; without even
10 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the above copyright notice for more information.
12 #
13 ############################################################################
14
15 """
16 Usage:
17
18 python NewSequence.py input.dcm output.dcm
19
20
21 Thanks to Robert Irie for code
22 """
23
24 import sys
25 import gdcm
26
27 if __name__ == "__main__":
28
29 file1 = sys.argv[1]
30 file2 = sys.argv[2]
31
32 r = gdcm.Reader()
33 r.SetFileName( file1 )
34 if not r.Read():
35 sys.exit(1)
36
37 f = r.GetFile()
38 ds = f.GetDataSet()
39 #tsis = gdcm.Tag(0x0008,0x2112) # SourceImageSequence
40
41 # Create a dataelement
42 de = gdcm.DataElement(gdcm.Tag(0x0010, 0x2180))
43 de.SetByteValue("Occupation", gdcm.VL(len("Occupation")))
44 de.SetVR(gdcm.VR(gdcm.VR.SH))
45
46 # Create an item
47 it=gdcm.Item()
48 it.SetVLToUndefined() # Needed to not popup error message
49 #it.InsertDataElement(de)
50 nds=it.GetNestedDataSet()
51 nds.Insert(de)
52
53 # Create a Sequence
54 sq=gdcm.SequenceOfItems().New()
55 sq.SetLengthToUndefined()
56 sq.AddItem(it)
57
58 # Insert sequence into data set
59 des=gdcm.DataElement(gdcm.Tag(0x0400,0x0550))
60 des.SetVR(gdcm.VR(gdcm.VR.SQ))
61 des.SetValue(sq.__ref__())
62 des.SetVLToUndefined()
63
64 ds.Insert(des)
65
66 w = gdcm.Writer()
67 w.SetFile( f )
68 w.SetFileName( file2 )
69 if not w.Write():
70 sys.exit(1)