Files
corning410_radiance_calibra…/1.2radiance_calibration_corning410.py
tangchao0503 fe8e2441c9 1. 融合300tc和hpi定标程序;
2. add:300tc中,从spatial bin1和spectral bin1的定标文件生成其他bin2的定标文件;
2023-07-27 11:50:05 +08:00

122 lines
4.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''
1、此版本所需文件dn影像和asd测定的积分球辐亮度曲线
2、处理过程不需要扣除暗电流因为dn影像在采集时已经扣除了暗电流
1通过辐亮度曲线生成定标文件
'''
import numpy as np
import pandas as pd
import sys, os, traceback
from library.image_reader_writer import ImageReaderWriter
from radiance_calibration_ui import Ui_MainWindow
from library.multithread import Worker
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication
from PyQt5.QtCore import Qt
class EnterWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(EnterWindow, self).__init__(parent)
self.setupUi(self)
self.radiance_calibration_object = RadianceCalibration()
# self.setWindowState(Qt.WindowMaximized) # 初始化时就最大化窗口
self.rad_bt.clicked.connect(self.select_rad)
self.dn_bt.clicked.connect(self.select_dn)
self.out_file_bt.clicked.connect(self.select_out_file)
self.operate_bt.clicked.connect(self.operate)
self.tmp_rad_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
self.tmp_dn_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
self.tmp_out_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
def select_rad(self):
if self.tmp_rad_file_path == None:
rad_file_path = QFileDialog.getOpenFileName(self, '选择asd辐亮度文件', os.path.dirname(__file__))[0]
self.tmp_rad_file_path = os.path.dirname(rad_file_path)
elif self.tmp_rad_file_path is not None:
rad_file_path = QFileDialog.getOpenFileName(self, '选择asd辐亮度文件', self.tmp_rad_file_path)[0]
self.tmp_rad_file_path = os.path.dirname(rad_file_path)
self.radiance_calibration_object.asd_radiance_file_path = rad_file_path
self.rad_le.setText(rad_file_path)
def select_dn(self):
if self.tmp_dn_file_path == None:
dn_file_path = QFileDialog.getOpenFileName(self, '选择dn影像', os.path.dirname(__file__))[0]
self.tmp_dn_file_path = os.path.dirname(dn_file_path)
elif self.tmp_dn_file_path is not None:
dn_file_path = QFileDialog.getOpenFileName(self, '选择dn影像', self.tmp_dn_file_path)[0]
self.tmp_dn_file_path = os.path.dirname(dn_file_path)
self.radiance_calibration_object.dn_file_path = dn_file_path
self.dn_le.setText(dn_file_path)
def select_out_file(self):
if self.tmp_out_file_path == None:
out_file_path = QFileDialog.getSaveFileName(self, '选择输出文件路径和文件名', os.path.dirname(__file__))[0]
self.tmp_out_file_path = os.path.dirname(out_file_path)
elif self.tmp_out_file_path is not None:
out_file_path = QFileDialog.getSaveFileName(self, '选择输出文件路径和文件名', self.tmp_out_file_path)[0]
self.tmp_out_file_path = os.path.dirname(out_file_path)
self.radiance_calibration_object.out_file_path = out_file_path
self.out_file_le.setText(out_file_path)
def operate(self):
self.radiance_calibration_object.operate()
class RadianceCalibration():
def __init__(self):
# asd_radiance_file = os.path.dirname(__file__) + '\\corning_radance.txt'
# img_file_path = os.path.dirname(__file__) + '\\jfq_dn'
# out_file = os.path.dirname(__file__) + '\\jfq_dn_gain'
self.asd_radiance_file_path = None
self.dn_file_path = None
self.img_data = None
self.out_file_path = None
def operate(self):
try:
# 读取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)
# 将影像所有行平均,得到一行(帧)影像
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]
ImageReaderWriter.write_img(self.out_file_path, gain)
except:
traceback.print_exc()
if __name__ == '__main__':
app = QApplication(sys.argv)
# 实例化主窗口
enter_window_instance = EnterWindow()
enter_window_instance.show()
sys.exit(app.exec_())