1. 融合300tc和hpi定标程序;

2. add:300tc中,从spatial bin1和spectral bin1的定标文件生成其他bin2的定标文件;
This commit is contained in:
tangchao0503
2023-07-19 23:02:42 +08:00
parent da52f56111
commit fe8e2441c9
5 changed files with 95 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import sys, os, traceback, re
import shutil
from radiance_calibration_ui import Ui_MainWindow
from library.multithread import Worker
from library.image_reader_writer import ImageReaderWriter
import sys, traceback
from osgeo import gdal
from scipy.interpolate import interp1d
@ -32,6 +33,7 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_bt.clicked.connect(self.select_out_file)
self.operate_bt.clicked.connect(self.operate)
self.dark_checkBox.stateChanged.connect(self.disabledDark)
self.tmp_rad_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
self.tmp_dn_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
@ -91,7 +93,14 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_le.setText(out_file_path)
def operate(self):
self.radiance_calibration_object.operate()
if(self.dark_checkBox.isChecked()):
self.radiance_calibration_object.operate()
else:
self.radiance_calibration_object.operate_without_dark()
def disabledDark(self, isEnable):
self.dark_le.setEnabled(isEnable)
self.dark_bt.setEnabled(isEnable)
class RadianceCalibration():
@ -251,15 +260,24 @@ class RadianceCalibration():
# 读取影像
img_proj, img_geotrans, self.img_data = self.read_img(self.dn_file_path)
dn_hdr = spectral.envi.read_envi_header(self.get_hdr_filename(self.dn_file_path))
# 重采样
f = interp1d(self.asd_radiance[:, 0], self.asd_radiance[:, 1])
# wave_destination = dn_hdr["wavelength"].removeprefix("{").removesuffix("}").split(",")
asd_radiance_interpolated = [f(float(i)) for i in dn_hdr["wavelength"]]
asd_radiance_interpolated2 = np.array(asd_radiance_interpolated)
# 将影像所有行平均,得到一行(帧)影像
img_data_ave = np.mean(self.img_data, axis=1)
gain = np.empty((img_data_ave.shape[0], 1, img_data_ave.shape[1]))
for i in range(gain.shape[2]):
gain[:, 0, i] = self.asd_radiance[:, 1] / img_data_ave[:, i]
gain[:, 0, i] = asd_radiance_interpolated2 / img_data_ave[:, i]
self.write_img(self.out_file_path, gain)
gain_name = os.path.join(self.out_file_path, "gain.bip")
ImageReaderWriter.write_img(gain_name, gain)
# self.write_img(gain_name, gain)
except:
traceback.print_exc()

View File

@ -73,6 +73,7 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_le.setText(out_file_path)
def operate(self):
self.radiance_calibration_object.operate()
@ -94,6 +95,7 @@ class RadianceCalibration():
# 读取asd辐亮度数据
data = pd.read_csv(self.asd_radiance_file_path, sep='\t', dtype=np.float64, header=None)
self.asd_radiance = np.array(data)
# 读取影像
img_proj, img_geotrans, self.img_data = ImageReaderWriter.read_img(self.dn_file_path)

55
change_bin_for_calfile.py Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env python
# coding: utf-8
import os
import glob
import sys, traceback, re
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
from library.image_reader_writer import ImageReaderWriter
import spectral
def write_img(dst_filename, data):
format = "ENVI"
driver = gdal.GetDriverByName(format)
RasterXSize = data.shape[2] # 遥感影像的sample列数
RasterYSize = data.shape[1] # 遥感影像的line行数
band = data.shape[0]
# driver.Create()函数中RasterXSize代表影像的sample列数RasterYSize代表影像的line行数
dst_ds = driver.Create(dst_filename, RasterXSize, RasterYSize, band, gdal.GDT_Float64,
options=["INTERLEAVE=BIP"])
for i in range(band):
dst_ds.GetRasterBand(i + 1).WriteArray(data[i, :, :]) # gdal的band从1开始所以dst_ds.GetRasterBand(i+1)
dst_ds = None
gainfilepath = r'D:\delete\254_11\offset.bip'
gainfilepathhdr = r'D:\delete\254_11\offset.bip.hdr'
gainfilepath_out = r'D:\delete\254_11\convert\offset.bip'
img_proj, img_geotrans, img_data = ImageReaderWriter.read_img(gainfilepath)
# # 空间bin
# gain = np.empty((300, 1, 688))
# for i in range(gain.shape[2]):
# if i <= 683:
# gain[:, :, i] = img_data[:, :, i*2] # 丢弃
# else:
# gain[:, :, i] = img_data[:, :, 683] # 重复
# 光谱bin
gain = np.empty((150, 1, 1368))
for i in range(gain.shape[0]):
gain[i, :, :] = (img_data[2 * i, :, :] + img_data[2 * i + 1, :, :]) / 2
header_tmp = spectral.envi.read_envi_header(gainfilepathhdr)
wavetmp = []
for i in range(150): # len(header_tmp["wavelength"])
x = (float(header_tmp["wavelength"][2 * i]) + float(header_tmp["wavelength"][2 * i + 1])) / 2
wavetmp.append(x)
print("%.4f, " % x, end='')
write_img(gainfilepath_out, gain)

View File

@ -2,9 +2,10 @@
# Form implementation generated from reading ui file 'radiance_calibration_ui.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
@ -73,6 +74,7 @@ class Ui_MainWindow(object):
self.dn_bt.setObjectName("dn_bt")
self.gridLayout.addWidget(self.dn_bt, 1, 2, 1, 1)
self.dark_checkBox = QtWidgets.QCheckBox(self.frame)
self.dark_checkBox.setChecked(True)
self.dark_checkBox.setObjectName("dark_checkBox")
self.gridLayout.addWidget(self.dark_checkBox, 2, 0, 1, 1)
self.dark_le = QtWidgets.QLineEdit(self.frame)
@ -144,8 +146,18 @@ class Ui_MainWindow(object):
self.rad_bt.setText(_translate("MainWindow", "浏览..."))
self.label_3.setText(_translate("MainWindow", "DN"))
self.dn_bt.setText(_translate("MainWindow", "浏览..."))
self.dark_checkBox.setText(_translate("MainWindow", "dark_checkBox"))
self.dark_checkBox.setText(_translate("MainWindow", "dark_300tc"))
self.dark_bt.setText(_translate("MainWindow", "浏览..."))
self.label_4.setText(_translate("MainWindow", "输出路径"))
self.out_file_bt.setText(_translate("MainWindow", "浏览..."))
self.operate_bt.setText(_translate("MainWindow", "执行"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

View File

@ -109,7 +109,7 @@
<item row="2" column="0">
<widget class="QCheckBox" name="dark_checkBox">
<property name="text">
<string>dark</string>
<string>dark_300tc</string>
</property>
<property name="checked">
<bool>true</bool>
@ -215,7 +215,7 @@
<x>0</x>
<y>0</y>
<width>964</width>
<height>23</height>
<height>26</height>
</rect>
</property>
</widget>