Search code examples
pythonnumpygdal

What is the range of values in the numpy array returned from gdal ReadAsArray?


I downloaded the BigEarthNet dataset and I read the TIFF images in python with gdal. Code below. The resulting array had values far above the 0-255 range I was expecting, so what is the range of the values?

band1 = imagePath + "/" + img + "/" + img + "_B02.tif"
band_ds = gdal.Open(band1,  gdal.GA_ReadOnly)
raster_band = band_ds.GetRasterBand(1)
blue = raster_band.ReadAsArray()
print(blue)

This is the output

[[284 388 554 ... 325 318 325]

 [211 213 297 ... 319 300 318]

 [227 206 245 ... 305 318 332]

 ...

 [309 612 920 ... 710 643 554]

 [259 626 862 ... 654 646 536]

 [260 608 730 ... 501 629 526]]

Solution

  • Seen as you already have gdal installed by the looks,

    gdalinfo <filename>
    

    will give you the stats on your file which will include the max and min of the values stored . The data in a tif can represent many things, for example a DEM stores values representing height in the raster band.

    The actual possible range of values depends on the datatype used to encode it. For example uint16 has a range of 0-65535 which I think I used in BIL format before.