优化亮场校正和暗场校正的流程和功能,亮场校正后增加坏像素校正。

This commit is contained in:
QI Mingxuan
2026-05-18 17:30:22 +08:00
parent ed0fe92cbe
commit ef83a7637a
2 changed files with 78 additions and 1373 deletions
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
@@ -479,14 +480,32 @@ namespace XP.Hardware.Detector.ViewModels
RaisePropertyChanged(nameof(IsParametersEditable));
}
/// <summary>
/// 校正采集帧数(固定 64 帧,确保校正质量)| Correction frame count (fixed 64 frames for quality)
/// </summary>
private const int CorrectionFrameCount = 64;
/// <summary>
/// 执行暗场校正 | Execute dark correction
/// </summary>
private async void ExecuteDarkCorrectionAsync()
{
// 弹出用户确认对话框 | Show user confirmation dialog
var confirmResult = MessageBox.Show(
"请确认射线源已关闭,即将开始暗场校正。\n\nPlease confirm the X-ray source is OFF before starting dark correction.",
"暗场校正确认 | Dark Correction Confirmation",
MessageBoxButton.OKCancel,
MessageBoxImage.Question);
if (confirmResult != MessageBoxResult.OK)
{
_logger?.Info("用户取消暗场校正 | User cancelled dark correction");
return;
}
var binningName = _selectedBinningIndex < BinningItems.Count ? BinningItems[_selectedBinningIndex].DisplayName : "?";
_logger?.Info("开始暗场校正,Binning={Binning}PGA={PGA},帧率={FrameRate} | Starting dark correction",
binningName, _selectedPga, _frameRate);
_logger?.Info("开始暗场校正,Binning={Binning}PGA={PGA},帧率={FrameRate},校正帧数={FrameCount} | Starting dark correction",
binningName, _selectedPga, _frameRate, CorrectionFrameCount);
// 显示进度条窗口 | Show progress window
var progressWindow = new ProgressWindow(
@@ -508,9 +527,9 @@ namespace XP.Hardware.Detector.ViewModels
return;
}
// 2. 执行暗场校正 | Execute dark correction
progressWindow.UpdateProgress("正在采集暗场数据... | Acquiring dark field data...", 30);
var result = await _detectorService.DarkCorrectionAsync(_avgFrames);
// 2. 执行暗场校正(固定 64 帧)| Execute dark correction (fixed 64 frames)
progressWindow.UpdateProgress("正在采集暗场数据64帧)... | Acquiring dark field data (64 frames)...", 30);
var result = await _detectorService.DarkCorrectionAsync(CorrectionFrameCount);
if (result.IsSuccess)
{
@@ -545,18 +564,49 @@ namespace XP.Hardware.Detector.ViewModels
if (!ValidateCorrectionParametersConsistency())
{
_logger?.Warn("暗场校正与亮场校正参数不一致,请重新进行暗场校正 | Parameter mismatch, please redo dark correction");
MessageBox.Show(
"当前参数与暗场校正时不一致,请重新进行暗场校正。\n\nCurrent parameters differ from dark correction. Please redo dark correction.",
"参数不一致 | Parameter Mismatch",
MessageBoxButton.OK,
MessageBoxImage.Warning);
DarkCorrectionDone = false;
return;
}
// 弹出确认对话框:物体移出视野 | Confirm object removed from field of view
var confirmObjectResult = MessageBox.Show(
"请确认物体已移出探测器视野。\n\nPlease confirm the object has been removed from the detector field of view.",
"亮场校正确认 | Light Correction Confirmation",
MessageBoxButton.OKCancel,
MessageBoxImage.Question);
if (confirmObjectResult != MessageBoxResult.OK)
{
_logger?.Info("用户取消亮场校正(物体确认)| User cancelled light correction (object confirmation)");
return;
}
// 弹出确认对话框:射线源已开启 | Confirm X-ray source is ON
var confirmRayResult = MessageBox.Show(
"请确认射线源已开启且稳定,即将开始亮场校正。\n\nPlease confirm the X-ray source is ON and stable before starting light correction.",
"亮场校正确认 | Light Correction Confirmation",
MessageBoxButton.OKCancel,
MessageBoxImage.Question);
if (confirmRayResult != MessageBoxResult.OK)
{
_logger?.Info("用户取消亮场校正(射线源确认)| User cancelled light correction (ray source confirmation)");
return;
}
var binningName = _selectedBinningIndex < BinningItems.Count ? BinningItems[_selectedBinningIndex].DisplayName : "?";
_logger?.Info("开始亮场校正,Binning={Binning}PGA={PGA},帧率={FrameRate} | Starting light correction",
binningName, _selectedPga, _frameRate);
_logger?.Info("开始亮场校正,Binning={Binning}PGA={PGA},帧率={FrameRate},校正帧数={FrameCount} | Starting light correction",
binningName, _selectedPga, _frameRate, CorrectionFrameCount);
// 显示进度条窗口 | Show progress window
var progressWindow = new ProgressWindow(
title: "亮场校正 | Light Correction",
message: "正在采集亮场数据... | Acquiring light field data...",
message: "正在采集亮场数据64帧)... | Acquiring light field data (64 frames)...",
isCancelable: false,
logger: _logger);
progressWindow.Show();
@@ -564,13 +614,28 @@ namespace XP.Hardware.Detector.ViewModels
IsBusy = true;
try
{
progressWindow.UpdateProgress("正在采集亮场数据... | Acquiring light field data...", 30);
var result = await _detectorService.GainCorrectionAsync(_avgFrames);
// 1. 执行亮场校正(固定 64 帧)| Execute light correction (fixed 64 frames)
progressWindow.UpdateProgress("正在采集亮场数据(64帧)... | Acquiring light field data (64 frames)...", 20);
var result = await _detectorService.GainCorrectionAsync(CorrectionFrameCount);
if (result.IsSuccess)
{
progressWindow.UpdateProgress("亮场校正完成 | Light correction completed", 100);
_logger?.Info("亮场校正完成 | Light correction completed");
_logger?.Info("亮场校正完成,开始执行坏像素校正 | Light correction completed, starting bad pixel correction");
// 2. 亮场校正完成后自动执行坏像素校正 | Auto execute bad pixel correction after light correction
progressWindow.UpdateProgress("正在执行坏像素校正... | Executing bad pixel correction...", 70);
var badPixelResult = await _detectorService.BadPixelCorrectionAsync();
if (badPixelResult.IsSuccess)
{
progressWindow.UpdateProgress("亮场校正及坏像素校正完成 | Light and bad pixel correction completed", 100);
_logger?.Info("亮场校正及坏像素校正全部完成 | Light correction and bad pixel correction all completed");
}
else
{
progressWindow.UpdateProgress("亮场校正完成,但坏像素校正失败 | Light correction done, bad pixel correction failed", 90);
_logger?.Error(badPixelResult.Exception, "坏像素校正失败:{Message} | Bad pixel correction failed: {Message}", badPixelResult.ErrorMessage);
}
}
else
{
File diff suppressed because it is too large Load Diff