Python 加载PIL.Image.fromArray时出现PIL溢出错误

Python 加载PIL.Image.fromArray时出现PIL溢出错误,python,pillow,Python,Pillow,我正在尝试使用Python3.4上的Pizzle 3.3.1存储大型图像。这些图像往往在1到4 GB的范围内,如uint8 RGB像素。Linux和OSX给了我同样的结果 from PIL import Image import numpy as np imgArray = np.random.randint(255, size=(39000, 35000, 3)).astype(np.uint8) print("buffer size:", imgArray.size) print("ima

我正在尝试使用Python3.4上的Pizzle 3.3.1存储大型图像。这些图像往往在1到4 GB的范围内,如uint8 RGB像素。Linux和OSX给了我同样的结果

from PIL import Image
import numpy as np

imgArray = np.random.randint(255, size=(39000, 35000, 3)).astype(np.uint8)
print("buffer size:", imgArray.size)
print("image max bytes:", 2**32)
pilImage = Image.fromarray(imgArray)
我得到以下输出

buffer size: 4095000000
image max bytes: 4294967296

Traceback (most recent call last):
  File "storeLargeImage.py", line 6, in <module>
    pilImage = Image.fromarray(imgArray)
  File "/home/mpesavento/miniconda3/lib/python3.4/site-packages/PIL/Image.py", line 2189, in fromarray
    return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
  File "/home/mpesavento/miniconda3/lib/python3.4/site-packages/PIL/Image.py", line 2139, in frombuffer
    return frombytes(mode, size, data, decoder_name, args)
  File "/home/mpesavento/miniconda3/lib/python3.4/site-packages/PIL/Image.py", line 2074, in frombytes
    im.frombytes(data, decoder_name, args)
  File "/home/mpesavento/miniconda3/lib/python3.4/site-packages/PIL/Image.py", line 736, in frombytes
    s = d.decode(data)
OverflowError: size does not fit in an int
缓冲区大小:4095000000
图像最大字节数:4294967296
回溯(最近一次呼叫最后一次):
文件“storeLargeImage.py”,第6行,在
pilImage=Image.fromarray(imgArray)
fromarray中的文件“/home/mpesavento/miniconda3/lib/python3.4/site packages/PIL/Image.py”,第2189行
从缓冲区返回(模式,大小,对象,“原始”,原始模式,0,1)
frombuffer中的文件“/home/mpesavento/miniconda3/lib/python3.4/site packages/PIL/Image.py”,第2139行
从字节返回(模式、大小、数据、解码器名称、参数)
文件“/home/mpesavento/miniconda3/lib/python3.4/site packages/PIL/Image.py”,第2074行,以frombytes为单位
im.frombytes(数据、解码器名称、参数)
文件“/home/mpesavento/miniconda3/lib/python3.4/site packages/PIL/Image.py”,第736行,以frombytes为单位
s=d.解码(数据)
溢出错误:大小不适合整数
缓冲区小于我认为PIL在Python3中使用的最大值,我认为它使用了uint32作为缓冲区长度。Python2中的PIL使用int32,使得最大值为2**31-1

在我们确定用于存储的编解码器之前,会出现此错误。例如,我想通过
pilImage.save(BytesIO(),format=“png”)


pilImage.save(BytesIO(),format=“tiff”)

如何保存大于2 GB(2147483647字节)的图像

编辑:
看起来应该是这样的。不知道为什么问题仍然出现。

我知道你问过PIL,但你可以试试。它专门处理大图像(比可用RAM大的图像),并且4gb文件应该没有问题。有一些

例如,我刚才做了:

$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.perlin(100000, 100000, uchar=True)
>>> x.write_to_file("x.tif", bigtiff=True)
>>>
$ ls -l x.tif
-rw-rw-r-- 1 john john 10000012844 Oct  7 11:43 x.tif

制作10 GB、8位、100000 x 100000像素的柏林噪声图像。当然,这需要一点时间——最后的写操作在我的笔记本电脑上大约需要三分钟,需要100MB的RAM。Python绑定是有文档记录的。你可以。

我知道你问过PIL,但你可以试试。它专门处理大图像(比可用RAM大的图像),并且4gb文件应该没有问题。有一些

例如,我刚才做了:

$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.perlin(100000, 100000, uchar=True)
>>> x.write_to_file("x.tif", bigtiff=True)
>>>
$ ls -l x.tif
-rw-rw-r-- 1 john john 10000012844 Oct  7 11:43 x.tif

制作10 GB、8位、100000 x 100000像素的柏林噪声图像。当然,这需要一点时间——最后的写操作在我的笔记本电脑上大约需要三分钟,需要100MB的RAM。Python绑定是有文档记录的。可以。

看起来它是一个。非纯Python的库可能仍然被限制为32位整数。看起来它是一个。非纯Python的库可能仍然被限制为32位整数。