[Gdal-dev] Read image file to Numpy, then output to image

Nate Jennings nate at deltateck.com
Tue May 8 18:28:09 EDT 2007


Hello,

I need some guidance on a path to take.  I am working on a little image
processing package written in Python for a class I teach in Remote Sensing.

>From other posts in other mail lists, I have been encouraged to look at gdal
for loading a multi-band image file into numpy, process it, then write it
out to an image format.

I am using Python 2.4, gdal-python-13.win32-py2.4 that I installed from the
.exe and numpy-1.0.2.win32-py2.4 from the exe and python image library
1.1.6win32-py2.4.  All of these have been installed correctly.  I would have
installed the 1.4.1 version of gdal, but I did not see an .exe and when I
tried to follow the instructions for changing the path and the gdal_data
environment variable, the import gdal was not recognized, so I chose a .exe
that seemed to work.

On this note, I attempted to follow the basic tutorial for loading an image
file.  (I tried a multi-band .TIF and ERDAS Imagine file).  The message I
received was--

img = gdal.gdal.Open('c:\\nate\\remote_sensing\\pyth_img_test.tif',
GA_ReadOnly)
AttributeError: 'module' object has no attribute 'gdal'

Here is my code below just for testing the reading of a multi-band image
file to then load it into a numpy array.  From here I want to do some pixel
by pixel processing.

-----------------------------

import Image, numpy, gdal, sys, os

img = gdal.Open('c:\\nate\\remote_sensing\\pyth_img_test.tif', GA_ReadOnly)

A = numpy.asarray(img)        #Convert the image to a numpy array

print A.shape
print A.size
print "Num Rows: " + str(A.shape[0])
print "Num Cols: " + str(A.shape[1])
print "Num bands: " + str(A.ndim)


------------------------------------

I also saw on the threads to access the FWTools, which I have loaded and
they seem to have slightly different methods of use.  My goal is to create a
little image processing package that I can give out to students to work with
multi-band imagery and do some of the things that FWTools has or OpenEV has,
but it a little more intuitive and can process more than 3 bands of
imagery.  Plus some of the documentation for some of the functions in
FWTools or OpenEV does not exist or the functions are a little cumbersome to
use.  I am also thinking about what will be required by the student to load
in order to use my python image processing application.  I want this to be
straight forward too...so if I am having difficulty with loading libraries,
having to change path variables, etc, then this is too much for the novie
Remote Sensing student.  I am not into compiliing my own libraries and will
be pushing my programming limits with writing C++, binding python to c++
code, etc.  I do have some programming experience with C++.  I was in an
algorithms class about 10 yrs ago while in grad school programming many of
the remote sensing algorthims....the problem was they were running under
OS/2 and were limited to the old ERDAS .LAN format.

I would appreciate some help in getting the image to read in a numpy array
as well as any feedback on re-directing my efforts if there is something
that I can tap into (such as FWTools libraries, OpenEV libraries).  It seems
that Frank has put alot of this together in different places, I am just
trying to get some of what is out there more combined to work on multi-band
imagery and RADAR (TIF, ERDAS Imagine files).

Thanks for any help.

Nate








-- 
http://www.jenningsplanet.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070508/4e5c3915/attachment.html


More information about the Gdal-dev mailing list