有没有办法将一张图像 row/column 读入 Python 中的数组?

Is there any way to read one image row/column into an array in Python?

我刚刚将一些 CT 重建软件从 IDL 翻译成 Python,这是我第一次使用 Python。该代码工作正常,只是速度慢得多。这在一定程度上是由于 IDL 允许我通过使用以下方法一次只读取一行图像来节省内存和时间:

image = read_tiff(filename, sub_rect = [0, slice, x, 1])

我需要从 1800 张不同的投影图像中每行读取一行,但据我所知,我只能通过读取整个图像然后将其转换为数组来创建图像数组。有没有什么技巧可以从一开始只读一行,因为我不需要其他 2047 行?

看起来 Christoph Gohlke (http://www.lfd.uci.edu/~gohlke/code/tifffile.py.html) 的 tifffile.py 可以胜任。

from tiffile import TiffFile

with TiffFile('test.tiff') as tif:
    for page in tif:
        image = page.asarray(memmap=True)
        print image[0,:,:]

如果我正确解释代码,这将提取文件中每一页的第一行,而无需将整个文件加载到内存中(通过 numpy.memmap)。