gdal+python 黑暗像元校正

“””
暗像元校正
方法:計算波段中的最小值進行暗像元校正
過程:1.影像DN值轉爲輻射能量值(L = DN*gain +bias)
2.計算相對反射率(ρ=π×D2×L/(ESUNI×COS(SZ)))
3.選擇波段最小值進行波段值運算(dataset.data =bands-bandsMin)
4.新建柵格數據寫入數據(driver = gdal.Create(self, *args, **kwargs))

@time:2018/4/2 9:40
@author:wujd
“””
from osgeo import gdal
import numpy as np
import os

打開數據文件

os.chdir(r”F:\Wujd\0330darkPixel\3285750”)
dataset = gdal.Open(“HJ1A-CCD1-451-63-20171202-L20003285750-1.TIF”)

獲取柵格數據的行列數,波段數,放射矩陣,投影信息

im_width = dataset.RasterXSize
im_height = dataset.RasterYSize
im_bands = dataset.RasterCount
im_geotrans = dataset.GetGeoTransform()
im_proj = dataset.GetProjection()
im_data = dataset.ReadAsArray(0,0,im_width,im_height)
type(im_data),im_data.shape

print(im_width, im_height,im_bands,im_geotrans,im_proj,im_data)

3.roi裁切後:遍歷部分區域像元,獲取最小值

os.chdir(r”F:\Wujd\0330darkPixel”)
datasetRoi = gdal.Open(“roi_min.tif”)
bandRoi = datasetRoi.GetRasterBand(1)
minValue = bandRoi.ComputeRasterMinMax()[0]
print(minValue)

1.計算DN轉爲輻射能量值——HJ1A-CCD1 b1:gain 1.4609 Bias 7.325 圖像的增益與偏置

gain =1.4609
bias = 7.3250
band = dataset.GetRasterBand(1)
data = band.ReadAsArray(0,0,im_width,im_height)
outband_L = (data-minValue)*gain +bias
print(“輻射能量值\n”,outband_L)

print(band.ComputeRasterMinMax())

2.計算相對反射率 ρ=π×D2×L/(ESUNI×COS(SZ))

days = 237 #拍攝衛片的日期在那一年的天數
sunEle = 21.945 #太陽高度角
ESUNI = 1914.324 #大氣頂層太陽輻照度(ESUNI)
D = 1-0.01674*np.sin(np.pi/180*(2*np.pi*(days-93.5)/360)) #日地天文單位距離D
sunZen = 90.000-sunEle #太陽天頂角
band_ref = np.pi*D*outband_L/(ESUNI*np.cos((np.pi/180)*sunZen)) #相對反射率

print(“相對反射率\n”,band_ref)

3.選則波段最小值

arr = band.ReadAsArray(0,0,im_width,im_height).astype(np.float16)
d = np.where(arr >0 )

print(d)
“”“

遍歷所有像元

i ,j= 0,0
print(im_height)
for i in range(0,im_height):
for j in range(0,im_width):
if band1[i][j]==0:
band1[i][j]=None
print(band1[i])
i += 1
j += 1
print(band1)
“”“

4.柵格創建寫入數據

driver = gdal.GetDriverByName(“GTiff”)
newdataset = driver.Create(“F://Wujd//0330darkPixel//newfile111.tif”,im_width,im_height,im_bands,6,options=[“INTERLEAVE=PIXEL”])
newdataset.SetGeoTransform(im_geotrans)
newdataset.SetProjection(im_proj)
newdataset.GetRasterBand(1).WriteArray(band_ref*10)

print(band.ComputeRasterMinMax())

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章