从 gdal ReadAsArray 返回的 numpy 数组中值的范围是多少?
What is the range of values in the numpy array returned from gdal ReadAsArray?
我下载了 BigEarthNet 数据集,并使用 gdal 在 python 中读取了 TIFF 图像。下面的代码。生成的数组的值远高于我预期的 0-255 范围,那么值的范围是多少?
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)
这是输出
[[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]]
如果它确实是一个 Numpy 数组,您可以通过以下方式获得 max/min 值:
numpy.amax(raster_band)
numpy.amin(raster_band)
看来您已经安装了 gdal,
gdalinfo <filename>
将为您提供文件的统计信息,其中包括存储值的最大值和最小值。 tif 中的数据可以表示很多东西,例如 DEM 存储表示栅格波段中高度的值。
值的实际可能范围取决于对其进行编码的数据类型。例如 uint16 的范围是 0-65535,我想我以前用过 BIL 格式。
From the sentinel-2 user guide:
Radiometric resolution is routinely expressed as a bit number,
typically in the range of 8 to 16 bits. The radiometric resolution of
the MSI instrument is 12 bit, enabling the image to be acquired over a
range of 0 to 4095 potential light intensity values.
我下载了 BigEarthNet 数据集,并使用 gdal 在 python 中读取了 TIFF 图像。下面的代码。生成的数组的值远高于我预期的 0-255 范围,那么值的范围是多少?
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)
这是输出
[[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]]
如果它确实是一个 Numpy 数组,您可以通过以下方式获得 max/min 值:
numpy.amax(raster_band)
numpy.amin(raster_band)
看来您已经安装了 gdal,
gdalinfo <filename>
将为您提供文件的统计信息,其中包括存储值的最大值和最小值。 tif 中的数据可以表示很多东西,例如 DEM 存储表示栅格波段中高度的值。
值的实际可能范围取决于对其进行编码的数据类型。例如 uint16 的范围是 0-65535,我想我以前用过 BIL 格式。
From the sentinel-2 user guide:
Radiometric resolution is routinely expressed as a bit number, typically in the range of 8 to 16 bits. The radiometric resolution of the MSI instrument is 12 bit, enabling the image to be acquired over a range of 0 to 4095 potential light intensity values.