我正在尝试从博客中重新创建一些作品http://sarvamblog.blogspot.com/2013/04/clustering-malware-corpus.html
import itertools
import glob
import numpy,scipy, os, array
from scipy.misc import imsave
for filename in list(glob.glob('file/*.file')):
f = open(filename,'rb');
#just want to make sure I get the right file'
print filename
ln = os.path.getsize(filename); # length of file in bytes
width = 256;
rem = ln%width;
a = array.array("B"); # uint8 array
a.fromfile(f,ln-rem);
f.close();
g = numpy.reshape(a,(len(a)/width,width));
g = numpy.uint8(g);
fpng = filename + ".png"
# make sure the png process and everything else is going'
print fpng
scipy.misc.imsave(fpng,g);`
,尽管这在1或2个文件上运行良好,但是一旦我扩展到数十个
,我就会遇到问题Traceback (most recent call last):
File "<stdin>", line 14, in <module>
File "/usr/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 120, in imsave
im = toimage(arr)
File "/usr/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 183, in toimage
image = Image.fromstring('L',shape,bytedata.tostring())
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1797, in fromstring
im.fromstring(data, decoder_name, args)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 590, in fromstring
d.setimage(self.im)
ValueError: tile cannot extend outside image
我认为我的问题不是:关闭scipy.misc.imsave或b:不重置载体。任何帮助将不胜感激
设法用try/除循环来弄清楚它。一旦我这样做,我就可以确定只有某些文件被取消。这些文件非常小(125个字节)。我的假设是它们太小,无法创建Scipy所需的所有信息
im.crop(box)⇒图像盒子是一个四翼,定义左,上,右和下像素坐标。
当我的代码中的较小比较小时,此错误发生了。