FW: [gdal-dev] accessing the histogram

Frank Warmerdam warmerdam at pobox.com
Wed Jan 21 13:11:57 EST 2009


Domazlicky, Eric wrote:
> There is no histogram in raster files sitting there for you to access.
> You have to calculate it yourself using the pixel data. Here is a good
> example of doing it in C#
> http://www.codeproject.com/KB/cs/Image_Histograms.aspx
> 
> I would familiarize yourself with the ReadRaster functions so you know
> how to actually access the pixel data of GDAL raster file so you can
> calculate the histogram.
> http://trac.osgeo.org/gdal/wiki/GdalOgrCsharpRaster

Folks,

As I noted on the fwtools list, there is a method in GDAL to get
histograms, though it normally just computes the histogram, more or
less as Eric notes above.  Before I wrote:

"""
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
"""

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