From 96c0da3c36acc587b7bd26317adf157c0c53e3b0 Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Sat, 24 Jun 2023 21:33:36 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BD=BF=E7=94=A8scipy.interpolate.interp?= =?UTF-8?q?1d=E9=87=8D=E9=87=87=E6=A0=B7=E8=83=BD=E9=87=8F=E6=9B=B2?= =?UTF-8?q?=E7=BA=BF=E5=88=B0=E5=BD=B1=E5=83=8F=E7=9A=84=E6=B3=A2=E6=AE=B5?= =?UTF-8?q?=EF=BC=9B=202.=20=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BD=BF=E7=94=A8s?= =?UTF-8?q?pectral.envi.read=5Fenvi=5Fheader=E8=AF=BB=E5=8F=96envi?= =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.1radiance_calibration_300tc.py | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) 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")