File: image_processing.rst

package info (click to toggle)
rasterio 1.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,744 kB
  • sloc: python: 22,881; sh: 795; makefile: 275; xml: 29
file content (39 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Interoperability
================

.. _imageorder: 

Image processing software
-------------------------
Some python image processing software packages
organize arrays differently than rasterio. The interpretation of a
3-dimension array read from ``rasterio`` is::

    (bands, rows, columns)

while image processing software like ``scikit-image``, ``pillow`` and ``matplotlib`` are generally ordered::

    (rows, columns, bands)

The number of rows defines the dataset's height, the columns are the dataset's width.

Numpy provides a way to efficiently swap the axis order and you can use the
following reshape functions to convert between raster and image axis order:

.. code:: python

    >>> 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)