[Gdal-dev] RE: How to efficiently read in a GDAL image into a matrix

Christopher Barker Chris.Barker at noaa.gov
Wed Nov 7 17:09:06 EST 2007


Nate Jennings wrote:
> You might try my website below, then go to Skillset--Application 
> Development.  I just put up a python script to do a mean filter on a
>  multiband image.  It uses the python gdal build of 1.4.2 that is
> posted on the gdal site and also requires the old Numeric libraries
> as well.

You should be able to do it with the latest GDAL and numpy as well.

> I do access individual pixels.  The code runs very slow (~5 min for a
> 400 x 600 image).

Is it necessary to do by individual pixels? numpy gives you a lot of
tools to work with whole arrays at a time, which would make it MUCH
faster. There are also a fair number of image processing algorithms out
there that use numpy -- ask on the numpy list if you can't find what you
need.

> I am looking to reproduce a similar function using c++ if and when I
 > can understand how the gdal libraries are used within c++.

If you do really need to go to C/C++, another option is to write code 
that works with numpy arrays as a python extension -- that way you can 
still write everything else in Python. There are lots of way to write 
C/C++ for use with numpy arrays:

SWIG
Pyrex
weave.blitz
f2py

See: http://www.scipy.org/PerformancePython

and the scipy and numpy lists for examples and discussion.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the gdal-dev mailing list