如何在python中以块的形式读取大图像? [英] How to read a large image in chunks in python?

查看:462
本文介绍了如何在python中以块的形式读取大图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算两个图像的像素值的差异,但我遇到了内存问题,因为我的图像非常大。有没有办法在python中我可以读取一个图像让我们一次说10x10块而不是尝试读取整个图像?我希望通过读取小块中的图像来解决内存问题,将这些块分配给numpy数组,然后使用pytables保存那些numpy数组以进行进一步处理。任何建议将不胜感激。

I'm trying to compute the difference in pixel values of two images, but I'm running into memory problems because the images I have are quite large. Is there way in python that I can read an image lets say in 10x10 chunks at a time rather than try to read in the whole image? I was hoping to solve the memory problem by reading an image in small chunks, assigning those chunks to numpy arrays and then saving those numpy arrays using pytables for further processing. Any advice would be greatly appreciated.

问候,

Berk

推荐答案

您可以使用numpy.memmap让操作系统决定将图像文件的哪些部分分页或分页。如果使用64位Python,虚拟内存空间与可用RAM相比是天文数字。

You can use numpy.memmap and let the operating system decide which parts of the image file to page in or out of RAM. If you use 64-bit Python the virtual memory space is astronomic compared to the available RAM.

这篇关于如何在python中以块的形式读取大图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆