''' 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_())