我有 4 个 numpy 数组格式的图像,其中每个图像都是 4D(61、73、61、11),最后一个维度对应于图像通道(在我的例子中为 11)。我使用 for 循环迭代通道,并在每次迭代时为每个图像创建一个包含 4 个图的子图。在 jupyter 笔记本中,我可以看到所有子图,但我想创建一个包含所有子图的图形,这样我就可以创建一个 png 而不是 11。这是 matplotlib 中的代码。
import maplotlib.pyplot as plt
center_slices = [s//2 for s in concat_img.shape[:1]] # take the middle slice
print(np.squeeze(concat_img[center_slices[0], :, :, 5]).shape)
for i in range(10):
f, axarr = plt.subplots(1, 4, figsize=(20,5), sharex=True);
f.suptitle('Different intensity normalisation methods on brain fMRI image dual_regression + ALFF derivatives')
img = axarr[0].imshow(np.squeeze(concat_img[:, :, center_slices[0], i]), cmap='gray');
axarr[0].axis('off')
axarr[0].set_title('Original image')
f.colorbar(img, ax=axarr[0])
img = axarr[1].imshow(np.squeeze(concat_img_white[:, :, center_slices[0], i]), cmap='gray');
axarr[1].axis('off')
axarr[1].set_title('Zero mean/unit stdev')
f.colorbar(img, ax=axarr[1])
img = axarr[2].imshow(np.squeeze(concat_img_zero_one[:, :, center_slices[0], i]), cmap='gray');
axarr[2].axis('off')
axarr[2].set_title('[0,1] rescaling')
f.colorbar(img, ax=axarr[2])
img = axarr[3].imshow(np.squeeze(concat_img_one_one[:, :, center_slices[0], i]), cmap='gray');
axarr[3].axis('off')
axarr[3].set_title('[-1,1] rescaling')
f.colorbar(img, ax=axarr[3])
f.subplots_adjust(wspace=0.05, hspace=0, top=0.8)
# plt.savefig('./TTT.{0:07d}.png'.format(i)) # save each subplot in png
plt.show();
GCT1015
相关分类