How to read a large image in chunks in python?

给你一囗甜甜゛ 提交于 2019-12-06 15:21:02

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.

zo3adams

If you have time to preprocess the images you can convert them to bitmap files (which will be large, not compressed) and then read particular sections of the file via offset as detailed here:

Load just part of an image in python

Conversion from any file type to bitmap can be done in Python with this code:

from PIL import Image
file_in = "inputCompressedImage.png"

img = Image.open(file_in)

file_out = "largeOutputFile.bmp"

img.save(file_out)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!