-
Notifications
You must be signed in to change notification settings - Fork 1
/
contour_image.py
executable file
·175 lines (119 loc) · 4.21 KB
/
contour_image.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python2.4
# $Id: contour_image.py 86 2007-11-12 22:11:40Z dwchin $
from __future__ import division
import sys
import pickle
from pylab import *
from EGSPhant import *
from MCDose import *
# Convenience functions to unpickle 3ddose and egsphant files,
# and to make isodose contour plots
def unpickle_dose(dosefilename):
df = open(dosefilename, 'ro')
d = pickle.load(df)
df.close()
return d
def unpickle_phant(phantfilename):
pf = open(phantfilename, 'ro')
p = pickle.load(pf)
pf.close()
return p
# These plotting routines take a normalization object so
# that the greyscale plot of the phantoms will have the
# same range if one plots different phantoms.
# Let's say there are 2 3ddose files each with a corresponding
# phantom. The phantoms may have a different set of materials.
# The normalization object is created by, for example:
#
# phanta = EGSPhant('foo.egsphant')
# phantb = EGSPhant('bar.egsphant')
# dosea = MCDose('foo.3ddose')
# doseb = MCDose('bar.3ddose')
# # set the lower end of the scale to be 0
# norm_scale = pylab.normalize(0, max(phanta.densityscan.max(), phantb.densityscan.max()))
# xy_plot(phanta, dosea, 13, 'foo', norm_scale)
# xy_plot(phantb, doseb, 13, 'bar', norm_scale)
def xy_plot(phant,dose,slice,titlestr,norm):
figure()
extent = phant.extent()[0:4]
im = imshow(phant.densityscan[slice,:,:],
interpolation='nearest', extent=extent,
cmap=cm.bone, origin='lower', norm=norm)
v = axis()
x, y = meshgrid(phant.x, phant.y)
levels = arange(0, dose.dose.max(), dose.dose.max()/15.)
cset = contour(x,y,dose.dose[slice,:,:], levels, cmap=cm.jet,
extent=extent, hold='on', origin='image')
for c in cset.collections:
c.set_linestyle('solid')
#clabel(cset, fontsize=12, inline=1)
colorbar(cset)
axis(v)
newtitlestr = '%s (z = %.2f cm)' % (titlestr, phant.z[slice])
title(newtitlestr)
xlabel('x (cm)')
ylabel('y (cm)')
ylim = get(gca(), 'ylim')
setp(gca(), ylim=ylim[::-1])
savefig(titlestr + '_xy')
show()
def xz_plot(phant,dose,slice,titlestr,norm):
figure()
maxz = 3.5
for i_maxz in range(len(phant.z)):
if phant.z[i_maxz] < maxz:
pass
else:
break
extent = (phant.x[0], phant.x[-1], phant.z[0], phant.z[i_maxz])
im = imshow(phant.densityscan[:i_maxz,slice,:],
interpolation='nearest', extent=extent,
cmap=cm.bone, origin='lower', norm=norm)
v = axis()
x, z = meshgrid(phant.x, phant.z[:i_maxz])
levels = arange(0., dose.dose.max(), dose.dose.max()/15.)
cset = contour(x,z,dose.dose[:i_maxz,slice,:], levels, cmap=cm.jet,
extent=extent, hold='on', origin='image')
for c in cset.collections:
c.set_linestyle('solid')
#clabel(cset, fontsize=12, inline=1)
colorbar(cset)
axis(v)
ylim = get(gca(), 'ylim')
setp(gca(), ylim=ylim[::-1])
newtitlestr = '%s (y = %.2f cm)' % (titlestr, phant.y[slice])
title(newtitlestr)
xlabel('x (cm)')
ylabel('z (cm)')
savefig(titlestr + '_xz')
show()
def yz_plot(phant,dose,slice,titlestr,norm):
figure()
maxz = 3.5
for i_maxz in range(len(phant.z)):
if phant.z[i_maxz] < maxz:
pass
else:
break
extent = (phant.y[0], phant.y[-1], phant.z[0], phant.z[i_maxz])
im = imshow(phant.densityscan[:i_maxz,:,slice],
interpolation='nearest', extent=extent,
cmap=cm.bone, origin='lower', norm=norm)
v = axis()
y, z = meshgrid(phant.y, phant.z[:i_maxz])
levels = arange(0, dose.dose.max(), dose.dose.max()/15.)
cset = contour(y,z,dose.dose[:i_maxz,:,slice], levels, cmap=cm.jet,
extent=extent, hold='on', origin='image')
for c in cset.collections:
c.set_linestyle('solid')
#clabel(cset, fontsize=8)
colorbar(cset)
axis(v)
ylim = get(gca(), 'ylim')
setp(gca(), ylim=ylim[::-1])
newtitlestr = '%s (x = %.2f cm)' % (titlestr, phant.x[slice])
title(newtitlestr)
xlabel('y (cm)')
ylabel('z (cm)')
savefig(titlestr + '_yz')
show()