[FWTools] accessing the histogram

Frank Warmerdam warmerdam at pobox.com
Wed Jan 21 11:40:59 EST 2009


Greg Fiske wrote:
> Hello folks,
> 
> Can somebody demonstrate how I can access the histogram of a
> raster image.  Ultimately, I'd like to dump it to a text file as
> well (I have many images to assess).

Greg,

You can get gdalinfo to report the histogram details using the -hist
option.

The results (mixed into the gdalinfo report) look like:

   256 buckets from -0.5 to 255.5:
   5824 0 0 0 0 0 0 0 4892 0 0 0 0 0 0 0 6665 0 0 0 0 0 0 0 0 8432 0 0 0 0 0 0 
0 9026 0 0 0 0 0 0 0 8988 0 0 0 0 0 0 0 9651 0 0 0 0 0 0 0 0 11196 0 0 0 0 0 0 
0 13316 0 0 0 0 0 0 0 14152 0 0 0 0 0 0 0 13986 0 0 0 0 0 0 0 14118 0 0 0 0 0 0 
0 0 15181 0 0 0 0 0 0 0 15247 0 0 0 0 0 0 0 14278 0 0 0 0 0 0 0 13076 0 0 0 0 0 
0 0 0 12244 0 0 0 0 0 0 0 11412 0 0 0 0 0 0 0 10168 0 0 0 0 0 0 0 8505 0 0 0 0 
0 0 0 0 6909 0 0 0 0 0 0 0 5860 0 0 0 0 0 0 0 4797 0 0 0 0 0 0 0 3864 0 0 0 0 0 
0 0 3348 0 0 0 0 0 0 0 0 2774 0 0 0 0 0 0 0 2368 0 0 0 0 0 0 0 2027 0 0 0 0 0 0 
0 1611 0 0 0 0 0 0 0 0 1306 0 0 0 0 0 0 0 1080 0 0 0 0 0 0 0 5843

If you need more control, and are willing to write a python script you
can adapt the one at:

   http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/histrep.py

Underlying this is the C++ method GDALRasterBand::GetHistogram():

http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8

Good luck,
-- 
---------------------------------------+--------------------------------------
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 FWTools mailing list