GDCM
2.4.5
Main Page
Related Pages
Namespaces
Classes
Files
Examples
HelloWorld.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
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
# Instanciate 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))
Generated on Fri Sep 25 2015 17:58:20 for GDCM by
1.8.9.1