GDCM: NewSequence.py

GDCM 3.2.7

NewSequence.py
1
14
15"""
16Usage:
17
18 python NewSequence.py input.dcm output.dcm
19
20
21Thanks to Robert Irie for code
22"""
23
24import sys
25import gdcm
26
27if __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.SetByteStringValue("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)
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
gdcm::SequenceOfItems
Class to represent a Sequence Of Items.
Definition gdcmSequenceOfItems.h:40
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::VR
VR class.
Definition gdcmVR.h:55
gdcm::Writer
Writer ala DOM (Document Object Model).
Definition gdcmWriter.h:49