diff --git a/1.1radiance_calibration_300tc.py b/1.1radiance_calibration_300tc.py index 2010e1b..32d3758 100644 --- a/1.1radiance_calibration_300tc.py +++ b/1.1radiance_calibration_300tc.py @@ -10,6 +10,8 @@ from radiance_calibration_ui import Ui_MainWindow from library.multithread import Worker import sys, traceback from osgeo import gdal +from scipy.interpolate import interp1d +import spectral from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication from PyQt5.QtCore import Qt @@ -142,9 +144,17 @@ class RadianceCalibration(): return os.path.splitext(file_path)[0] + ".bip.hdr" def write_fields_to_hdrfile(self, fields, hdr_file): + header_tmp = spectral.envi.read_envi_header(hdr_file) + with open(hdr_file, "a", encoding='utf-8') as f: for key in fields.keys(): - f.write(key + " = " + fields[key] + "\n") + if key in header_tmp or key == "description": + continue + + if type(fields[key]) == list: + f.write(key + " = {" + ", ".join(fields[key]) + "}\n") + else: + f.write(key + " = " + fields[key] + "\n") def process_hdr(self, hdr_file_path, envi_header_dict): self.write_fields_to_hdrfile(envi_header_dict, self.get_hdr_filename(hdr_file_path)) @@ -193,9 +203,23 @@ class RadianceCalibration(): # 读取影像 img_proj, img_geotrans, self.img_data = self.read_img(self.dn_file_path) - dn_hdr = self.get_envi_header_dict(self.get_hdr_filename(self.dn_file_path)) + # dn_hdr = self.get_envi_header_dict(self.get_hdr_filename(self.dn_file_path)) + dn_hdr = spectral.envi.read_envi_header(self.get_hdr_filename(self.dn_file_path)) img_dark_proj, img_dark_geotrans, self.img_dark_data = self.read_img(self.dark_file_path) - dark_hdr = self.get_envi_header_dict(self.get_hdr_filename(self.dark_file_path)) + # dark_hdr = self.get_envi_header_dict(self.get_hdr_filename(self.dark_file_path)) + dark_hdr = spectral.envi.read_envi_header(self.get_hdr_filename(self.dark_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) + + notuse = np.zeros((asd_radiance_interpolated2.shape[0], 2)) + notuse[:, 0] = np.array([float(i) for i in dn_hdr["wavelength"]]) + notuse[:, 1] =asd_radiance_interpolated2 + np.savetxt(os.path.join(self.out_file_path, "asd_radiance_interpolated.txt"), notuse) + # 将影像所有行平均,得到一行(帧)影像 img_data_ave = np.mean(self.img_data, axis=1) @@ -203,12 +227,11 @@ class RadianceCalibration(): # 去除暗电流 img_data_ave_rmdark = img_data_ave - img_dark_data_ave - img_dark_data_ave = img_dark_data_ave + 50 gain = np.empty((img_data_ave_rmdark.shape[0], 1, img_data_ave_rmdark.shape[1])) offset = np.empty((img_data_ave_rmdark.shape[0], 1, img_data_ave_rmdark.shape[1])) for i in range(gain.shape[2]): - gain[:, 0, i] = self.asd_radiance[:, 1] / img_data_ave_rmdark[:, i] + gain[:, 0, i] = asd_radiance_interpolated2 / img_data_ave_rmdark[:, i] offset[:, 0, i] = img_dark_data_ave[:, i] gain_name = os.path.join(self.out_file_path, "gain.bip")