代码
import io
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure("Data", frameon=False)
plt.imshow(i, cmap='gray')
canvas = fig.canvas
plt.axis('off')
# 设置画布大小,单位英寸,1英寸=100px
fig.set_size_inches(272 / 100, 256 / 100)
plt.gca().xaxis.set_major_locator(plt.NullLocator()) # plt.gca()表示获取当前子图"Get Current Axes"。
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0)
plt.margins(0, 0)
buffer = io.BytesIO()
canvas.print_png(buffer)
data = buffer.getvalue()
buffer.write(data)
image = np.asarray(Image.open(buffer))
Comments | NOTHING