GDCM 3.2.1

HelloWorld.py
1
14
15"""
16 Hello World !
17"""
18
19 import gdcm
20 import sys
21
22 if __name__ == "__main__":
23
24 # verbosity:
25 #gdcm.Trace.DebugOn()
26 #gdcm.Trace.WarningOn()
27 #gdcm.Trace.ErrorOn()
28
29 # Get the filename from the command line
30 filename = sys.argv[1]
31
32 # Instantiate a gdcm.Reader
33 # This is the main class to handle any type of DICOM object
34 # You should check for gdcm.ImageReader for reading specifically DICOM Image file
35 r = gdcm.Reader()
36 r.SetFileName( filename )
37 # If the reader fails to read the file, we should stop !
38 if not r.Read():
39 print "Not a valid DICOM file"
40 sys.exit(1)
41
42 # Get the DICOM File structure
43 file = r.GetFile()
44
45 # Get the DataSet part of the file
46 dataset = file.GetDataSet()
47
48 # Ok let's print it !
49 print dataset
50
51 # Use StringFilter to print a particular Tag:
52 sf = gdcm.StringFilter()
53 sf.SetFile(r.GetFile())
54
55 # Check if Attribute exist
56 print dataset.FindDataElement( gdcm.Tag(0x0028,0x0010))
57
58 # Let's print it as string pair:
59 print sf.ToStringPair(gdcm.Tag(0x0028,0x0010))
gdcm::Reader
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
gdcm::StringFilter
StringFilter.
Definition gdcmStringFilter.h:30
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39