尝试使用scipy.misc.imsave将numpy数组保存为图像时出现溢出错误

时间:2013-11-08 18:54:18

标签: numpy scipy python-imaging-library

我正在尝试查看numpy.float32的71290x71290数组。当我尝试使用matplotlib以交互方式查看它时,我的计算机内存不足,所以我试图将其保存为图像文件并在ipython之外查看。通过阅读其他SO帖子,以下内容应该有效:

import numpy as np
W = np.zeros((71290, 71290), dtype='float32')    
from scipy.misc import imsave
imsave('test.png', W)

但是最后一行给了我一个溢出错误:

  

OverflowError:size不适合int

这是完整的堆栈跟踪:

---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
/home/agittens/Documents/langmodel/<ipython-input-4-bf9f2254f869> in <module>()
----> 1 imsave('test.png', W)

/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.pyc in imsave(name, arr)
    160 
    161     """
--> 162     im = toimage(arr)
    163     im.save(name)
    164     return

/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.pyc in toimage(arr, high, low, cmin, cmax, pal, mode, channel_axis)
    235         if mode in [None, 'L', 'P']:
    236             bytedata = bytescale(data,high=high,low=low,cmin=cmin,cmax=cmax)
--> 237             image = Image.frombytes('L',shape,bytedata.tostring())
    238             if pal is not None:
    239                 image.putpalette(asarray(pal,dtype=uint8).tostring())

/usr/lib/python2.7/dist-packages/PIL/Image.pyc in fromstring(mode, size, data, decoder_name, *args)
   1795 
   1796     im = new(mode, size)
-> 1797     im.fromstring(data, decoder_name, args)
   1798     return im
   1799 

/usr/lib/python2.7/dist-packages/PIL/Image.pyc in fromstring(self, data, decoder_name, *args)
    589         d = _getdecoder(self.mode, decoder_name, args)
    590         d.setimage(self.im)
--> 591         s = d.decode(data)
    592 
    593         if s[0] >= 0:

OverflowError: size does not fit in an int

0 个答案:

没有答案
相关问题