I'm trying to open a tiff stack using gdal in python. It is a single file, within which are mutliple tiff files. When I open it in ImageJ, I can scroll through the stack. But doing "gdal.Open(file).ReadAsArray() only loads the first tiff file. Is there a way I can load the whole stack?

有帮助吗?

解决方案

Iterate over GetSubDatasets and (in case all TIFF pages have the same dimensions) create a single numpy array:

import numpy, gdal, gdalconst
dataset = gdal.Open("multipage.tiff", gdalconst.GA_ReadOnly)
data = numpy.array([gdal.Open(name, gdalconst.GA_ReadOnly).ReadAsArray()
                    for name, descr in dataset.GetSubDatasets()])
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top