我想拼接8张9450x75600像素的图像(即75600x75600像素)。
import sys
import PIL
from PIL import Image
PIL.Image.MAX_IMAGE_PIXELS = 9331200000
ListeImage=['test1.tif','test2.tif','test3.tif','test4.tif','test5.tif','test6.tif','test7.tif','test8.tif']
images = [Image.open(x) for x in ListeImage]
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_im = Image.new('RGB', (total_width, max_height))
y_offset = 0
for im in images:
new_im.paste(im, (0,y_offset))
y_offset += im.size[0]
new_im.save('TOTAL'+str(y_offset)+'.tif')
但是我遇到了这个错误...
Traceback (most recent call last):
File "C:\Python27\MergeImages.py", line 21, in <module>
new_im.save('test'+str(bande[0])+'.tif')
(...)
File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 626, in _pack
return struct.pack(self._endian + fmt, *values)
error: integer out of range for 'L' format code
我认为这是一个内存问题。如何解决?
x
偏移量而不是y
。 - Mark Setchell