Вот что у меня есть на данный момент:
Код: Выделить всё
# build fig
figsize, dpi = self._calc_fig_size_res(img_height)
fig = plt.Figure(figsize=figsize)
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.imshow(torch.from_numpy(S).flip(0), cmap = cmap)
fig.subplots_adjust(left = 0, right = 1, bottom = 0, top = 1)
ax.axis('tight'); ax.axis('off')
# export
fig.savefig(export_path, dpi = dpi)
# open image as PIL object
img = Image.open(export_path)
Код: Выделить всё
pil_img = Image.frombytes('RGB', canvas.get_width_height(), canvas.tostring_rgb())
Подробнее здесь: https://stackoverflow.com/questions/573 ... ving-image
Мобильная версия