1. 使用scipy.interpolate.interp1d重采样能量曲线到影像的波段;
2. 修改:使用spectral.envi.read_envi_header读取envi头文件;
This commit is contained in:
@ -10,6 +10,8 @@ from radiance_calibration_ui import Ui_MainWindow
|
|||||||
from library.multithread import Worker
|
from library.multithread import Worker
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
from osgeo import gdal
|
from osgeo import gdal
|
||||||
|
from scipy.interpolate import interp1d
|
||||||
|
import spectral
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication
|
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
@ -142,8 +144,16 @@ class RadianceCalibration():
|
|||||||
return os.path.splitext(file_path)[0] + ".bip.hdr"
|
return os.path.splitext(file_path)[0] + ".bip.hdr"
|
||||||
|
|
||||||
def write_fields_to_hdrfile(self, fields, hdr_file):
|
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:
|
with open(hdr_file, "a", encoding='utf-8') as f:
|
||||||
for key in fields.keys():
|
for key in fields.keys():
|
||||||
|
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")
|
f.write(key + " = " + fields[key] + "\n")
|
||||||
|
|
||||||
def process_hdr(self, hdr_file_path, envi_header_dict):
|
def process_hdr(self, hdr_file_path, envi_header_dict):
|
||||||
@ -193,9 +203,23 @@ class RadianceCalibration():
|
|||||||
|
|
||||||
# 读取影像
|
# 读取影像
|
||||||
img_proj, img_geotrans, self.img_data = self.read_img(self.dn_file_path)
|
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)
|
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)
|
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_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]))
|
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]))
|
offset = np.empty((img_data_ave_rmdark.shape[0], 1, img_data_ave_rmdark.shape[1]))
|
||||||
for i in range(gain.shape[2]):
|
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]
|
offset[:, 0, i] = img_dark_data_ave[:, i]
|
||||||
|
|
||||||
gain_name = os.path.join(self.out_file_path, "gain.bip")
|
gain_name = os.path.join(self.out_file_path, "gain.bip")
|
||||||
|
Reference in New Issue
Block a user