我只想在没有填充和轴的情况下保存图片 以下是代码:
#-*- coding:utf-8 -*-
import SimpleITK as sitk
import numpy as np
import matplotlib.pyplot as plt
url = r"G:to\my\filename.mha"
path = r'F:\image\s.png'
image = sitk.ReadImage(url)
max_index = image.GetDepth()
max_width = image.GetWidth()
max_height = image.GetHeight()
print(max_index,max_width,max_height)
# As list of 2D numpy arrays which cannot be modified (no data copied)
xxx = sitk.GetArrayViewFromImage(image)[75,:,:]
zzz = plt.imshow(xxx,cmap = 'gray')
plt.savefig(path)
plt.show()
答案 0 :(得分:0)
从这里接受我的回答:How to completely remove the white space around a scatterplot?
用以下代码替换最后三行:
fig,ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
ax.imshow(xxx)
ax.axis('tight')
ax.axis('off')
plt.savefig(path)
plt.show()