NumPy

NumPy is an extremely fast, multidimensional Python array processor designed specifically for Python and scientific computing but is written in C. It is available via PyPI or as a wheel file (available at http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) and installs easily. In addition to its amazing speed, the magic of NumPy includes its interaction with other libraries. NumPy can exchange data with GDAL, Shapely, the Python Imaging Library (PIL), and many other scientific computing Python libraries in other fields.

As a quick example of NumPy's ability, we'll combine it with GDAL to read in our sample satellite image and then create a histogram of it. The interface between GDAL and NumPy is a GDAL module called gdal_array, which has NumPy as a dependency. Numeric is the legacy name of the NumPy module. The gdal_array module imports NumPy.

In the following example, we'll use gdal_array, which imports NumPy, to read the image in as an array, grab the first band, and save it back out as a JPEG image:

>>> from osgeo import gdal_array
>>> srcArray = gdal_array.LoadFile("SatImage.tif")
>>> band1 = srcArray[0]
>>> gdal_array.SaveArray(band1, "band1.jpg", format="JPEG")

This operation gives us the following grayscale image in OpenEV:

NumPy
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset