界面优化
This commit is contained in:
@ -989,7 +989,12 @@ class WaterQualityInversionPipeline:
|
||||
if not GDAL_AVAILABLE:
|
||||
raise ImportError("GDAL未安装,无法保存影像文件")
|
||||
|
||||
height, width, n_bands = image_array.shape
|
||||
# 兼容 (H,W) 和 (H,W,C) 两种 shape 格式
|
||||
if image_array.ndim == 2:
|
||||
height, width = image_array.shape
|
||||
n_bands = 1
|
||||
else:
|
||||
height, width, n_bands = image_array.shape
|
||||
|
||||
# 获取驱动
|
||||
driver = gdal.GetDriverByName('ENVI')
|
||||
@ -1100,11 +1105,8 @@ class WaterQualityInversionPipeline:
|
||||
Returns:
|
||||
numpy数组或None,1表示水域,0表示非水域
|
||||
"""
|
||||
# 获取图像尺寸
|
||||
if isinstance(image_shape, np.ndarray):
|
||||
img_height, img_width = image_shape.shape[:2]
|
||||
else:
|
||||
img_height, img_width = image_shape
|
||||
# 获取图像尺寸(统一从 shape 元组中提取前两个维度,兼容 (H,W)、(H,W,C)、(B,H,W) 等多种格式)
|
||||
img_height, img_width = image_shape[0], image_shape[1]
|
||||
|
||||
if water_mask is None:
|
||||
# 如果water_mask为None,使用步骤1生成的dat格式掩膜
|
||||
@ -1362,6 +1364,19 @@ class WaterQualityInversionPipeline:
|
||||
interpolated_bands.append(band_data)
|
||||
continue
|
||||
|
||||
# 兼容中文和各种格式
|
||||
raw_interp = str(interpolation_method).lower()
|
||||
if 'nearest' in raw_interp or '邻近' in raw_interp or '最邻近' in raw_interp:
|
||||
interpolation_method = 'nearest'
|
||||
elif 'bilinear' in raw_interp or '线性' in raw_interp or '双线性' in raw_interp:
|
||||
interpolation_method = 'bilinear'
|
||||
elif 'spline' in raw_interp or '样条' in raw_interp or 'rbf' in raw_interp:
|
||||
interpolation_method = 'spline'
|
||||
elif 'kriging' in raw_interp or '克里金' in raw_interp:
|
||||
interpolation_method = 'kriging'
|
||||
else:
|
||||
interpolation_method = 'nearest'
|
||||
|
||||
# 对需要插值的像素进行插值
|
||||
if interpolation_method == 'nearest':
|
||||
# 邻近插值
|
||||
@ -1591,6 +1606,18 @@ class WaterQualityInversionPipeline:
|
||||
|
||||
step_start_time = time.time()
|
||||
try:
|
||||
# 兼容中文和各种格式
|
||||
raw_method = str(method).lower()
|
||||
if 'kutser' in raw_method:
|
||||
method = 'kutser'
|
||||
elif 'goodman' in raw_method:
|
||||
method = 'goodman'
|
||||
elif 'hedley' in raw_method:
|
||||
method = 'hedley'
|
||||
elif 'sugar' in raw_method:
|
||||
method = 'sugar'
|
||||
# 其余方法(subtract_nir, regression_slope, oxygen_absorption)保持原值
|
||||
|
||||
# 如果未启用,直接跳过处理并把原始影像路径作为后续流程输入
|
||||
if not enabled:
|
||||
print("已设置跳过去除耀斑(enabled=False),将直接使用原始影像。")
|
||||
@ -1807,6 +1834,16 @@ class WaterQualityInversionPipeline:
|
||||
del corrected_bands
|
||||
|
||||
elif method == "sugar":
|
||||
# 强行转换暗号,兼容中文和各种格式
|
||||
raw_method = str(sugar_glint_mask_method).lower()
|
||||
if 'cdf' in raw_method or '累积' in raw_method:
|
||||
sugar_glint_mask_method = 'cdf'
|
||||
elif 'otsu' in raw_method or '大津' in raw_method:
|
||||
sugar_glint_mask_method = 'otsu'
|
||||
else:
|
||||
# 默认回退到 cdf 确保不崩溃
|
||||
sugar_glint_mask_method = 'cdf'
|
||||
|
||||
print(f"使用方法: SUGAR (迭代次数={sugar_iter}, 掩膜方法={sugar_glint_mask_method})")
|
||||
|
||||
# 确定输出路径
|
||||
@ -3603,6 +3640,29 @@ class WaterQualityInversionPipeline:
|
||||
Returns:
|
||||
预处理后的CSV文件路径
|
||||
"""
|
||||
# 兼容中文和各种格式
|
||||
raw_p = str(preprocess_method).lower()
|
||||
if raw_p == 'none' or '无' in raw_p or '跳过' in raw_p:
|
||||
preprocess_method = 'None'
|
||||
elif raw_p == 'mms' or 'minmax' in raw_p or '最大最小' in raw_p:
|
||||
preprocess_method = 'MMS'
|
||||
elif raw_p == 'ss' or '标准' in raw_p or '标准化' in raw_p:
|
||||
preprocess_method = 'SS'
|
||||
elif raw_p == 'snv' or '标准正态' in raw_p:
|
||||
preprocess_method = 'SNV'
|
||||
elif raw_p == 'ma' or '移动' in raw_p:
|
||||
preprocess_method = 'MA'
|
||||
elif raw_p == 'sg' or 'savitzky' in raw_p or '平滑' in raw_p:
|
||||
preprocess_method = 'SG'
|
||||
elif raw_p == 'msc' or '多元散射' in raw_p:
|
||||
preprocess_method = 'MSC'
|
||||
elif raw_p == 'd1' or 'd2' or 'dt' or '导数' in raw_p:
|
||||
preprocess_method = {'d1': 'D1', 'd2': 'D2', 'dt': 'DT'}.get(raw_p, raw_p.upper())
|
||||
elif raw_p == 'ct' or '去趋势' in raw_p:
|
||||
preprocess_method = 'CT'
|
||||
else:
|
||||
preprocess_method = preprocess_method # 保持原值
|
||||
|
||||
# 如果不需要预处理,直接返回原文件
|
||||
if preprocess_method == 'None':
|
||||
return csv_path
|
||||
|
||||
Reference in New Issue
Block a user