GDCM  2.2.6
GetPortionCSAHeader.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 GetPortionCSAHeader.py input.dcm
19 
20 Footnote:
21  SIEMENS is not publishing any information on the CSA header. So any info extracted
22  is at your own risk.
23 """
24 
25 import sys
26 import gdcm
27 
28 if __name__ == "__main__":
29 
30  file = sys.argv[1]
31 
32  r = gdcm.Reader()
33  r.SetFileName( file )
34  if not r.Read():
35  sys.exit(1)
36 
37  ds = r.GetFile().GetDataSet()
38  csa_t1 = gdcm.CSAHeader()
39  csa_t2 = gdcm.CSAHeader()
40  #print csa
41  t1 = csa_t1.GetCSAImageHeaderInfoTag();
42  print t1
43  t2 = csa_t2.GetCSASeriesHeaderInfoTag();
44  print t2
45  # Let's do it for t1:
46  if ds.FindDataElement( t1 ):
47  csa_t1.LoadFromDataElement( ds.GetDataElement( t1 ) )
48  print csa_t1
49 
50  # Now let's pretend we are only interested in B_value and DiffusionGradientDirection entries:
51  bvalues = csa_t1.GetCSAElementByName( "B_value" ) # WARNING: it is case sensitive !
52  print bvalues
53 
54  diffgraddir = csa_t1.GetCSAElementByName( "DiffusionGradientDirection" ) # WARNING: it is case sensitive !
55  print diffgraddir
56 
57  # repeat for t2 if you like it:
58  if ds.FindDataElement( t2 ):
59  csa_t2.LoadFromDataElement( ds.GetDataElement( t2 ) )
60  # print csa_t2
61 
62  gdt = csa_t2.GetCSAElementByName( "GradientDelayTime" )
63  print gdt
64 
65  bv = gdt.GetByteValue();
66  #print bv
67  str = bv.GetPointer()
68  print str.split("\\")

Generated on Sat Dec 21 2013 05:56:15 for GDCM by doxygen 1.8.5
SourceForge.net Logo