[gdal-dev] What Statistics Are Returned By GDAL.Dataset.GetRasterBand(...).GetStatistics(...) ?
Peter Willis
pwillis at aslenv.com
Thu Oct 3 10:21:58 PDT 2019
Hello,
I am using osgeo.gdal python module to load and get stats from image
bands.
While working with the, python, 'GetStatistics(...)' function I noticed that
the returned values seemed a bit off.
A snippet of code is shown below.
I compared the statistics returned in python by the function to band
statistics in ENVI image processing package for the same input file.
The results are shown below.
I am wondering if I am missing information regarding some key data filtering
feature in GDAL GetStatistics.
What statistics are GDAL returning?
#####################################
## PYTHON CODE
#####################################
src_ds = gdal.Open(image_path )
for bnd in range(1, src_ds.RasterCount+1 ):
item = {}
print("[ GETTING BAND ]: ", bnd)
srcband=None
srcband = src_ds.GetRasterBand(bnd)
if srcband is None:
continue
bnddata=srcband.ReadAsArray()
stats = srcband.GetStatistics( 0, 1 )
if stats is None:
continue
else:
print('put the values in a dictionary')
##GDAL stats##
#item['min'] = stats[0]
#item['max'] = stats[1]
#item['mean'] = stats[2]
#item['stdev'] = stats[3]
##numpy array stats##
#item['min'] = bnddata.min()
#item['max'] = bnddata.max()
#item['mean'] = bnddata.mean()
#item['stdev'] = bnddata.std()
###################################
#END PYTHON CODE
###################################
/*..........................................................................
............................................................................
..*/
ENVI Statistics test returns these vales for each channel
Channel Min Max Mean Stdev
Band 1 0.000000 0.441641 0.135938 0.095007
Band 2 0.000000 0.477772 0.134556 0.096385
Band 3 0.000000 0.512614 0.143145 0.108702
Band 4 0.000000 0.574203 0.159381 0.128212
Band 5 0.000000 1.286870 0.190917 0.159562
Band 6 0.000000 1.368695 0.218191 0.191100
Band 7 0.000000 1.208142 0.179098 0.158407
/*..........................................................................
............................................................................
..*/
GDAL GetStatistics in Python 3.0 Returns
[
{'min': 0.10543035715818, 'max': 0.35029646754265, 'mean': 0.19733288299107,
'stdev': 0.03141020073449},
{'min': 0.087364979088306, 'max': 0.36481207609177, 'mean':
0.19531263034662, 'stdev': 0.040193729911813},
{'min': 0.066563792526722, 'max': 0.40562310814857, 'mean':
0.20773722116063, 'stdev': 0.060965329408999},
{'min': 0.057971999049187, 'max': 0.49459338188171, 'mean':
0.23126556845189, 'stdev': 0.084854378172706},
{'min': 0.052771702408791, 'max': 0.57949388027191, 'mean':
0.27695694029464, 'stdev': 0.11419731959916},
{'min': 0.033055797219276, 'max': 0.67045384645462, 'mean':
0.31645853188616, 'stdev': 0.14756091787453}
]
/*..........................................................................
............................................................................
..*/
Using NumPy Stats Functions in Python 3.0
np.min()
np.max()
np.mean()
np.std()
Return the following values after converting the previous GDAL bands to
'NumPy.Array' and using the NumPy functions
(Values look similar to ENVI)
[
{'min': 0.0, 'max': 0.44164082, 'mean': 0.13593808, 'stdev': 0.09500719},
{'min': 0.0, 'max': 0.47777158, 'mean': 0.13455594, 'stdev': 0.09638489},
{'min': 0.0, 'max': 0.51261353, 'mean': 0.14314489, 'stdev': 0.108702265},
{'min': 0.0, 'max': 0.57420313, 'mean': 0.15938139, 'stdev': 0.12821245},
{'min': 0.0, 'max': 1.2868699, 'mean': 0.19091722, 'stdev': 0.15956147},
{'min': 0.0, 'max': 1.3686954, 'mean': 0.21819061, 'stdev': 0.1911003}
]
More information about the gdal-dev
mailing list