我正在使用此code处理整个幻灯片图像(.svs格式)。此代码在NUM_TOP_TILES = 50至NUM_TOP_TILES = 12000
时运行良好。由于整个幻灯片图像的尺寸非常大,在这种情况下,如果我增加NUM_TOP_TILES>12000
,则会出错
OverflowError:大小不适合int错误。
使用大图像时,Pillow
这是一个非常常见的问题。 github
和StackOverFlow
中有很多解决方案,但我无法解决我的问题。根据我的分析,以下功能中的Image.fromarray()
中的Pillow
导致了此问题。如果有人提出任何解决此问题的解决方案,那将是很大的帮助。我已经提供了相关的function
和error traceback
供您参考。
功能
:def np_to_pil(np_img):
"""
Convert a NumPy array to a PIL Image.
Args:
np_img: The image represented as a NumPy array.
Returns:
The NumPy array converted to a PIL Image.
"""
if np_img.dtype == "bool":
np_img = np_img.astype("uint8") * 255
elif np_img.dtype == "float64":
np_img = (np_img * 255).astype("uint8")
return Image.fromarray(np_img)
错误回溯
回溯(最近通话最近一次):
File "WsiToImagePatch.py", line 35, in np_to_pil
return Image.fromarray(np_img)
File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 2536, in fromarray
return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 2479, in frombuffer
return frombytes(mode, size, data, decoder_name, args)
File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 2412, in frombytes
im.frombytes(data, decoder_name, args)
File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 812, in frombytes
s = d.decode(data)
OverflowError: size does not fit in an int