1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
############################################################################
#
# Program: GDCM (Grassroots DICOM). A DICOM library
#
# Copyright (c) 2006-2011 Mathieu Malaterre
# All rights reserved.
# See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
############################################################################
"""
Usage:
python GetPortionCSAHeader.py input.dcm
Footnote:
SIEMENS is not publishing any information on the CSA header. So any info extracted
is at your own risk.
"""
import sys
import gdcm
if __name__ == "__main__":
file = sys.argv[1]
r = gdcm.Reader()
r.SetFileName( file )
if not r.Read():
sys.exit(1)
ds = r.GetFile().GetDataSet()
csa_t1 = gdcm.CSAHeader()
csa_t2 = gdcm.CSAHeader()
#print csa
t1 = csa_t1.GetCSAImageHeaderInfoTag();
print t1
t2 = csa_t2.GetCSASeriesHeaderInfoTag();
print t2
# Let's do it for t1:
if ds.FindDataElement( t1 ):
csa_t1.LoadFromDataElement( ds.GetDataElement( t1 ) )
print csa_t1
# Now let's pretend we are only interested in B_value and DiffusionGradientDirection entries:
bvalues = csa_t1.GetCSAElementByName( "B_value" ) # WARNING: it is case sensitive !
print bvalues
diffgraddir = csa_t1.GetCSAElementByName( "DiffusionGradientDirection" ) # WARNING: it is case sensitive !
print diffgraddir
# repeat for t2 if you like it:
if ds.FindDataElement( t2 ):
csa_t2.LoadFromDataElement( ds.GetDataElement( t2 ) )
# print csa_t2
gdt = csa_t2.GetCSAElementByName( "GradientDelayTime" )
print gdt
bv = gdt.GetByteValue();
#print bv
str = bv.GetPointer()
print str.split("\\")
|