Compare commits

4 Commits

Author SHA1 Message Date
32ccb25a0e add:
(1)在生成的300tc定标文件中添加生成时间;
(2)添加版本号:2.1;
2023-07-27 13:35:31 +08:00
fe8e2441c9 1. 融合300tc和hpi定标程序;
2. add:300tc中,从spatial bin1和spectral bin1的定标文件生成其他bin2的定标文件;
2023-07-27 11:50:05 +08:00
da52f56111 注释代码 2023-06-24 21:35:11 +08:00
96c0da3c36 1. 使用scipy.interpolate.interp1d重采样能量曲线到影像的波段;
2. 修改:使用spectral.envi.read_envi_header读取envi头文件;
2023-06-24 21:33:36 +08:00
5 changed files with 127 additions and 15 deletions

View File

@ -8,8 +8,12 @@ import sys, os, traceback, re
import shutil import shutil
from radiance_calibration_ui import Ui_MainWindow from radiance_calibration_ui import Ui_MainWindow
from library.multithread import Worker from library.multithread import Worker
from library.image_reader_writer import ImageReaderWriter
import sys, traceback import sys, traceback
from osgeo import gdal from osgeo import gdal
from scipy.interpolate import interp1d
import spectral
import time
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
@ -30,6 +34,7 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_bt.clicked.connect(self.select_out_file) self.out_file_bt.clicked.connect(self.select_out_file)
self.operate_bt.clicked.connect(self.operate) self.operate_bt.clicked.connect(self.operate)
self.dark_checkBox.stateChanged.connect(self.disabledDark)
self.tmp_rad_file_path = None # 用于保存当前路径,下次打开就默认在此路径下 self.tmp_rad_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
self.tmp_dn_file_path = None # 用于保存当前路径,下次打开就默认在此路径下 self.tmp_dn_file_path = None # 用于保存当前路径,下次打开就默认在此路径下
@ -89,7 +94,14 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_le.setText(out_file_path) self.out_file_le.setText(out_file_path)
def operate(self): def operate(self):
if(self.dark_checkBox.isChecked()):
self.radiance_calibration_object.operate() self.radiance_calibration_object.operate()
else:
self.radiance_calibration_object.operate_without_dark()
def disabledDark(self, isEnable):
self.dark_le.setEnabled(isEnable)
self.dark_bt.setEnabled(isEnable)
class RadianceCalibration(): class RadianceCalibration():
@ -142,8 +154,17 @@ 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)
fields['generated time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
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 +214,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 +238,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")
@ -228,15 +262,24 @@ 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 = spectral.envi.read_envi_header(self.get_hdr_filename(self.dn_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)
# 将影像所有行平均,得到一行(帧)影像 # 将影像所有行平均,得到一行(帧)影像
img_data_ave = np.mean(self.img_data, axis=1) img_data_ave = np.mean(self.img_data, axis=1)
gain = np.empty((img_data_ave.shape[0], 1, img_data_ave.shape[1])) gain = np.empty((img_data_ave.shape[0], 1, img_data_ave.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[:, i] gain[:, 0, i] = asd_radiance_interpolated2 / img_data_ave[:, i]
self.write_img(self.out_file_path, gain) gain_name = os.path.join(self.out_file_path, "gain.bip")
ImageReaderWriter.write_img(gain_name, gain)
# self.write_img(gain_name, gain)
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -73,6 +73,7 @@ class EnterWindow(QMainWindow, Ui_MainWindow):
self.out_file_le.setText(out_file_path) self.out_file_le.setText(out_file_path)
def operate(self): def operate(self):
self.radiance_calibration_object.operate() self.radiance_calibration_object.operate()
@ -94,6 +95,7 @@ class RadianceCalibration():
# 读取asd辐亮度数据 # 读取asd辐亮度数据
data = pd.read_csv(self.asd_radiance_file_path, sep='\t', dtype=np.float64, header=None) data = pd.read_csv(self.asd_radiance_file_path, sep='\t', dtype=np.float64, header=None)
self.asd_radiance = np.array(data) self.asd_radiance = np.array(data)
# 读取影像 # 读取影像
img_proj, img_geotrans, self.img_data = ImageReaderWriter.read_img(self.dn_file_path) img_proj, img_geotrans, self.img_data = ImageReaderWriter.read_img(self.dn_file_path)

55
change_bin_for_calfile.py Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env python
# coding: utf-8
import os
import glob
import sys, traceback, re
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
from library.image_reader_writer import ImageReaderWriter
import spectral
def write_img(dst_filename, data):
format = "ENVI"
driver = gdal.GetDriverByName(format)
RasterXSize = data.shape[2] # 遥感影像的sample列数
RasterYSize = data.shape[1] # 遥感影像的line行数
band = data.shape[0]
# driver.Create()函数中RasterXSize代表影像的sample列数RasterYSize代表影像的line行数
dst_ds = driver.Create(dst_filename, RasterXSize, RasterYSize, band, gdal.GDT_Float64,
options=["INTERLEAVE=BIP"])
for i in range(band):
dst_ds.GetRasterBand(i + 1).WriteArray(data[i, :, :]) # gdal的band从1开始所以dst_ds.GetRasterBand(i+1)
dst_ds = None
gainfilepath = r'D:\delete\254_11\offset.bip'
gainfilepathhdr = r'D:\delete\254_11\offset.bip.hdr'
gainfilepath_out = r'D:\delete\254_11\convert\offset.bip'
img_proj, img_geotrans, img_data = ImageReaderWriter.read_img(gainfilepath)
# # 空间bin
# gain = np.empty((300, 1, 688))
# for i in range(gain.shape[2]):
# if i <= 683:
# gain[:, :, i] = img_data[:, :, i*2] # 丢弃
# else:
# gain[:, :, i] = img_data[:, :, 683] # 重复
# 光谱bin
gain = np.empty((150, 1, 1368))
for i in range(gain.shape[0]):
gain[i, :, :] = (img_data[2 * i, :, :] + img_data[2 * i + 1, :, :]) / 2
header_tmp = spectral.envi.read_envi_header(gainfilepathhdr)
wavetmp = []
for i in range(150): # len(header_tmp["wavelength"])
x = (float(header_tmp["wavelength"][2 * i]) + float(header_tmp["wavelength"][2 * i + 1])) / 2
wavetmp.append(x)
print("%.4f, " % x, end='')
write_img(gainfilepath_out, gain)

View File

@ -2,9 +2,10 @@
# Form implementation generated from reading ui file 'radiance_calibration_ui.ui' # Form implementation generated from reading ui file 'radiance_calibration_ui.ui'
# #
# Created by: PyQt5 UI code generator 5.13.0 # Created by: PyQt5 UI code generator 5.15.7
# #
# WARNING! All changes made in this file will be lost! # WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
@ -73,6 +74,7 @@ class Ui_MainWindow(object):
self.dn_bt.setObjectName("dn_bt") self.dn_bt.setObjectName("dn_bt")
self.gridLayout.addWidget(self.dn_bt, 1, 2, 1, 1) self.gridLayout.addWidget(self.dn_bt, 1, 2, 1, 1)
self.dark_checkBox = QtWidgets.QCheckBox(self.frame) self.dark_checkBox = QtWidgets.QCheckBox(self.frame)
self.dark_checkBox.setChecked(True)
self.dark_checkBox.setObjectName("dark_checkBox") self.dark_checkBox.setObjectName("dark_checkBox")
self.gridLayout.addWidget(self.dark_checkBox, 2, 0, 1, 1) self.gridLayout.addWidget(self.dark_checkBox, 2, 0, 1, 1)
self.dark_le = QtWidgets.QLineEdit(self.frame) self.dark_le = QtWidgets.QLineEdit(self.frame)
@ -139,13 +141,23 @@ class Ui_MainWindow(object):
def retranslateUi(self, MainWindow): def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) MainWindow.setWindowTitle(_translate("MainWindow", "Corning Calibration v2.1"))
self.label.setText(_translate("MainWindow", "ASD辐亮度")) self.label.setText(_translate("MainWindow", "ASD辐亮度"))
self.rad_bt.setText(_translate("MainWindow", "浏览...")) self.rad_bt.setText(_translate("MainWindow", "浏览..."))
self.label_3.setText(_translate("MainWindow", "DN")) self.label_3.setText(_translate("MainWindow", "DN"))
self.dn_bt.setText(_translate("MainWindow", "浏览...")) self.dn_bt.setText(_translate("MainWindow", "浏览..."))
self.dark_checkBox.setText(_translate("MainWindow", "dark_checkBox")) self.dark_checkBox.setText(_translate("MainWindow", "dark_300tc"))
self.dark_bt.setText(_translate("MainWindow", "浏览...")) self.dark_bt.setText(_translate("MainWindow", "浏览..."))
self.label_4.setText(_translate("MainWindow", "输出路径")) self.label_4.setText(_translate("MainWindow", "输出路径"))
self.out_file_bt.setText(_translate("MainWindow", "浏览...")) self.out_file_bt.setText(_translate("MainWindow", "浏览..."))
self.operate_bt.setText(_translate("MainWindow", "执行")) self.operate_bt.setText(_translate("MainWindow", "执行"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>Corning Calibration v2.1</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
@ -109,7 +109,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="dark_checkBox"> <widget class="QCheckBox" name="dark_checkBox">
<property name="text"> <property name="text">
<string>dark</string> <string>dark_300tc</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
@ -215,7 +215,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>964</width> <width>964</width>
<height>23</height> <height>26</height>
</rect> </rect>
</property> </property>
</widget> </widget>