-
Notifications
You must be signed in to change notification settings - Fork 4
/
getdicominfo
executable file
·40 lines (37 loc) · 1.32 KB
/
getdicominfo
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
#!/opt/local/bin/python
#
# $Author: frederic $
# $Date: 2011/08/31 21:07:13 $
# $Id: getdicominfo,v 1.8 2011/08/31 21:07:13 frederic Exp $
#
import sys
import dicom
def getsiemensmrheader(theplan):
SiemensCSAHeader2=theplan[0x0029,0x1020].value
startposition=SiemensCSAHeader2.find('### ASCCONV BEGIN ###')+len('### ASCCONV BEGIN ###')
endposition=SiemensCSAHeader2.find('### ASCCONV END ###')
InterestingSiemensHeader=SiemensCSAHeader2[startposition:endposition].splitlines()
datadict={}
for theline in InterestingSiemensHeader[1:]:
thepair=theline.split()
datadict[thepair[0]]=thepair[2]
return datadict
# read in the datafile
if len(sys.argv)!=2:
print "usage: getdicominfo inputfile"
exit()
filename=sys.argv[1]
plan=dicom.read_file(filename)
timestr=float(plan.AcquisitionTime)
thetr=float(plan.RepetitionTime)
timeconv=3600*(int(timestr/10000)%100)+60*(int(timestr/100)%100)+timestr%100+(timestr-int(timestr))
acqnum=plan.AcquisitionNumber
#thesiemensheader=getsiemensmrheader(plan)
#slicethickness=thesiemensheader['sSliceArray.asSlice[0].dThickness']
#inplanerot=thesiemensheader['sSliceArray.asSlice[0].dInPlaneRot']
try:
elementnumber=plan[0x0051,0x100f].value
except KeyError:
print timestr, thetr, acqnum
else:
print timestr, thetr, acqnum, elementnumber