我想禁用(或尽可能降低)plt.imsave()
的压缩。我只想快速转出几乎立即重用的PNG图像。
任何想法如何做到这一点?
(我正在使用agg后端)
答案 0 :(得分:2)
从它的外观来看,matplotlib's pyplot.imsave()
不支持压缩选项。您应该使用Python Imaging Library PIL。
以下是使用Image.save()
将numpy数组保存为PNG的最小示例:
import numpy as np, Image as im
img = im.fromarray(np.random.rand(640,480), mode='I')
img.save('test.png', format='PNG', bits=8)
PNG writer's options的文档记录很少,但它允许您修改ZLIB编码器字典等事实看起来很有希望。