互操作性

图像处理软件

一些Python图像处理软件包对数组的组织方式与栅格不同。三维数组的解释 rasterio 是::

(bands, rows, columns)

而图像处理软件如 scikit-imagepillowmatplotlib 通常是:

(rows, columns, bands)

行数定义了数据集的高度,列是数据集的宽度。

numpy提供了一种有效交换轴顺序的方法,您可以使用以下重塑函数在栅格和图像轴顺序之间进行转换:

>>> import rasterio
>>> from rasterio.plot import reshape_as_raster, reshape_as_image

>>> raster = rasterio.open("tests/data/RGB.byte.tif").read()
>>> raster.shape
(3, 718, 791)

>>> image = reshape_as_image(raster)
>>> image.shape
(718, 791, 3)

>>> raster2 = reshape_as_raster(image)
>>> raster2.shape
(3, 718, 791)