def plot_overlays(atlas, b0, cmaps):
plt.rcParams.update({'axes.labelsize': 'x-large',
'axes.titlesize': 'x-large'})
if b0.shape == (182, 218, 182):
x = [78, 90, 100]
y = [82, 107, 142]
z = [88, 103, 107]
else:
shap = b0.shape
x = [int(shap[0]*0.35), int(shap[0]*0.51), int(shap[0]*0.65)]
y = [int(shap[1]*0.35), int(shap[1]*0.51), int(shap[1]*0.65)]
z = [int(shap[2]*0.35), int(shap[2]*0.51), int(shap[2]*0.65)]
coords = (x, y, z)
labs = ['Sagittal Slice (YZ fixed)',
'Coronal Slice (XZ fixed)',
'Axial Slice (XY fixed)']
var = ['X', 'Y', 'Z']
# create subplot for first slice
# and customize all labels
idx = 0
for i, coord in enumerate(coords):
for pos in coord:
idx += 1
ax = plt.subplot(3, 3, idx)
ax.set_title(var[i] + " = " + str(pos))
if i == 0:
image = ndimage.rotate(b0[pos, :, :], 90)
atl = ndimage.rotate(atlas[pos, :, :], 90)
elif i == 1:
image = ndimage.rotate(b0[:, pos, :], 90)
atl = ndimage.rotate(atlas[:, pos, :], 90)
else:
image = b0[:, :, pos]
atl = atlas[:, :, pos]
if idx % 3 == 1:
ax.set_ylabel(labs[i])
ax.yaxis.set_ticks([0, image.shape[0]/2, image.shape[0] - 1])
ax.xaxis.set_ticks([0, image.shape[1]/2, image.shape[1] - 1])
min_val, max_val = get_min_max(image)
plt.imshow(atl, interpolation='none', cmap=cmaps[0], alpha=0.5)
plt.imshow(image, interpolation='none', cmap=cmaps[1], alpha=0.5,
vmin=min_val, vmax=max_val)
fig = plt.gcf()
fig.set_size_inches(12.5, 10.5, forward=True)
return fig
评论列表
文章目录