我还没有找到这个简单问题的答案。请帮帮忙。如何将Qcal (数字列表)转换为TIFF图像?我发现的一切都不管用。
import math
import numpy as np
from osgeo import gdal
substr1 = 'RADIANCE_MULT_BAND_10'
substr2 = 'RADIANCE_ADD_BAND_10'
substr3 = 'K1_CONSTANT_BAND_10'
substr4 = 'K2_CONSTANT_BAND_10'
RADIANCE_MULT_BAND_10 = 1
RADIANCE_ADD_BAND_10 = 1
K1_CONSTANT_BAND_10 = 1
K2_CONSTANT_BAND_10 = 1
with open('LC08_L1TP_180028_20170623_20170630_01_T1_MTL.txt') as file:
for line in file:
if substr1 in line:
startIndex = line.find('=')
RADIANCE_MULT_BAND_10 = float((line[startIndex+2:]))
if substr2 in line:
startIndex = line.find('=')
RADIANCE_ADD_BAND_10 = float((line[startIndex + 2:]))
if substr3 in line:
startIndex = line.find('=')
K1_CONSTANT_BAND_10 = float((line[startIndex + 2:]))
if substr4 in line:
startIndex = line.find('=')
K2_CONSTANT_BAND_10 = float((line[startIndex + 2:]))
ds = gdal.Open("B10.tif")
Qcal = np.array(ds.GetRasterBand(1).ReadAsArray()) # Quantized and calibrated standard product pixel values (DN)
for i in range(Qcal.shape[0]):
for j in range(Qcal.shape[1]):
Qcal[i][j] = RADIANCE_MULT_BAND_10 * Qcal[i][j] + RADIANCE_ADD_BAND_10
Qcal[i][j] = K2_CONSTANT_BAND_10 / math.log1p(K1_CONSTANT_BAND_10/Qcal+1)发布于 2018-03-19 07:49:13
您要修改现有的映像吗?
如果是这样的话,您应该使用更新选项打开它,如下所示
gdal.Open("B10.tif", gdal.GA_Update)接下来,就像正在做的那样,对np数组进行修改。实际上,您只是在编辑numpy数组Qcal,而不是tif中的实际光栅带。
现在,要将修改保存到相同的带中,可以执行以下操作
ds.GetRasterBand(1).WriteArray(Qcal)这是将更新的Qcal数组写入tif的栅格带。
如果您想要保存为一个新的图像
您可以创建现有映像的副本,并将Qcal数组保存到其中,如下所示
driver = gdal.GetDriverByName('Gtiff')
dst_ds = driver.CreateCopy("example.tif", ds, 1)
dst_ds.GetRasterBand(1).WriteArray(Qcal)https://stackoverflow.com/questions/49354590
复制相似问题