d5d964d115
滤波类:GaussianBlur(Sigma)、Bilateral(SigmaSpace)、 BandPass(FilterType,Order)、ShockFilter(Dt) 边缘检测:Sobel(Direction,KernelSize,Scale)、 HorizontalEdge(Method,Sensitivity)、Kirsch(Scale)
72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
// ============================================================================
|
|
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
|
// 文件名: GaussianBlurProcessor.cs
|
|
// 描述: 高斯模糊算子,用于图像平滑和降噪
|
|
// 功能:
|
|
// - 高斯核卷积平滑
|
|
// - 可调节核大小和标准差
|
|
// - 有效去除高斯噪声
|
|
// - 保持边缘相对清晰
|
|
// 算法: 高斯滤波器卷积
|
|
// 作者: 李伟 wei.lw.li@hexagon.com
|
|
// ============================================================================
|
|
|
|
using Emgu.CV;
|
|
using Emgu.CV.Structure;
|
|
using XP.ImageProcessing.Core;
|
|
using Serilog;
|
|
|
|
namespace XP.ImageProcessing.Processors;
|
|
|
|
/// <summary>
|
|
/// 高斯模糊算子(支持 8 位和 16 位灰度图像)
|
|
/// </summary>
|
|
public class GaussianBlurProcessor<TDepth> : ImageProcessorBase<TDepth>
|
|
where TDepth : struct, IComparable
|
|
{
|
|
private static readonly ILogger _logger = Log.ForContext<GaussianBlurProcessor<TDepth>>();
|
|
|
|
public GaussianBlurProcessor()
|
|
{
|
|
Name = LocalizationHelper.GetString("GaussianBlurProcessor_Name");
|
|
Description = LocalizationHelper.GetString("GaussianBlurProcessor_Description");
|
|
}
|
|
|
|
protected override void InitializeParameters()
|
|
{
|
|
Parameters.Add("KernelSize", new ProcessorParameter(
|
|
"KernelSize",
|
|
LocalizationHelper.GetString("GaussianBlurProcessor_KernelSize"),
|
|
typeof(int),
|
|
5,
|
|
1,
|
|
31,
|
|
LocalizationHelper.GetString("GaussianBlurProcessor_KernelSize_Desc")));
|
|
|
|
Parameters.Add("Sigma", new ProcessorParameter(
|
|
"Sigma",
|
|
LocalizationHelper.GetString("GaussianBlurProcessor_Sigma"),
|
|
typeof(double),
|
|
1.5,
|
|
0.1,
|
|
10.0,
|
|
LocalizationHelper.GetString("GaussianBlurProcessor_Sigma_Desc")) { IsAdvanced = true });
|
|
_logger.Debug("InitializeParameters");
|
|
}
|
|
|
|
public override Image<Gray, TDepth> Process(Image<Gray, TDepth> inputImage)
|
|
{
|
|
int kernelSize = GetParameter<int>("KernelSize");
|
|
double sigma = GetParameter<double>("Sigma");
|
|
|
|
if (kernelSize % 2 == 0) kernelSize++;
|
|
|
|
var result = inputImage.Clone();
|
|
CvInvoke.GaussianBlur(inputImage, result,
|
|
new System.Drawing.Size(kernelSize, kernelSize), sigma);
|
|
|
|
_logger.Debug("Process: KernelSize = {KernelSize}, Sigma = {Sigma}", kernelSize, sigma);
|
|
return result;
|
|
}
|
|
}
|