2016-04-14 74 views
1

我想将一个numpy矩阵保存为一个.png图像,但我不能这样做使用matplotlib,因为我想保留其原始大小(该matplotlib不会这样做是因为它增加了比例和白色背景等)。任何人都知道我可以使用numpy或PIL来解决这个问题吗?由于在Python中将矩阵转换为图像

+0

参见'fig.figimage' http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.figimage – tacaswell

+0

http://stackoverflow.com/questions/9910388/matplotlib-plot-small-image -without-resampling/9915223#9915223 – tacaswell

+0

另请参阅http://stackoverflow.com/questions/902761/saving-a-numpy-array-as-an-image –

回答

1

使用SciPy的库解决

进口scipy.misc

...(代码)

scipy.misc.imsave(名称,数组格式)

scipy.misc.imsave('name.ext',array)其中ext是扩展名,因此决定了图像将被存储的格式。