【问题标题】:Image processing in Python – without loading the entire image into memoryPython中的图像处理——无需将整个图像加载到内存中
【发布时间】:2014-03-28 15:46:25
【问题描述】:
我正在寻找一个 python 库,它允许我从 TIF 图像中检索图像数据,而无需将整个图像加载到内存中。
我尝试使用numpy.memmap,但在文件中查找图像数据时遇到了困难。任何意见将是有益的。谢谢。
【问题讨论】:
标签:
python
image-processing
memory-management
numpy
scipy
【解决方案1】:
我有两个建议给你:
-
将图像数据分块读入Python:
with open('path/to/image-data.tif', 'rb') as tif:
while True:
chunk = tif.read(4096)
if not chunk:
break
考虑使用 NumExpr 进行处理:https://github.com/pydata/numexpr
...在内部,NumExpr 使用自己的矢量化虚拟机,该虚拟机是围绕分块读取策略设计的,以便有效地对内存中大小最佳的数据块进行操作。如果调整得当,它可以轻松击败幼稚的 NumPy 操作。
希望对你有帮助,祝你好运