[gdal-dev] Reading/Interpreting multi band Tiffs
Frank Warmerdam
warmerdam at pobox.com
Tue Sep 23 11:43:45 EDT 2008
Tom Kazimiers wrote:
> Hi there,
>
> up to now I only faced Tiff images with palette information. It was
> relatively easy to read and display everything - I use RasterIO for the
> one available band and the color table.
> Now I want to load and display multi band Tiff images - namely the bands
> red, green and blue. For what I have understood a pixels RGB value is
> then the value from the red band at the pixels position as red value,
> the green value from the green band and so on. So do I understand it
> right that I have to make three RasterIO calls to get the color of one
> pixel - one call for each band? Exists there maybe a more convenient way
> like making one call and getting back the color?
Tom,
There is also a RasterIO() method on the Dataset which allows
fetching all the bands in one request. In C++ this is:
http://www.gdal.org/classGDALDataset.html#e077c53268d2272eebed10b891a05743
In C:
http://www.gdal.org/gdal_8h.html#764cb93a266ada902b13c2bdad3f7037
In Python you would use:
def ReadRaster(*args, **kwargs):
"""
ReadRaster(self, int xoff, int yoff, int xsize, int ysize, int buf_len,
int buf_xsize=0, int buf_ysize=0, GDALDataType buf_type=0,
int band_list=0) -> CPLErr
"""
return _gdal.Dataset_ReadRaster(*args, **kwargs)
eg.
rgb_buffer = dataset.ReadRaster(0,0,100,100,gdal.GDT_Byte,[1,2,3])
to read a 3 band buffer for the region 1,2,3 in "Byte" format.
Note that the C/C++ APIs read in band interleave format by default.
So the buffer would be filled with all the red, followed by tall the
green followed by all the blue. If you want pixel interleaving
you will need to carefully select appropriate nPixelSpace, nLineSpace
and nBandSpace parameters.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the gdal-dev
mailing list