规范类名及命名空间名称
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� DifferenceProcessor.cs
|
||||
// æ��è¿°: 差分è¿�ç®—ç®—å�,用于边缘检测和å�˜åŒ–检æµ?
|
||||
// 功能:
|
||||
// - 对图�进行差分��
|
||||
// - 支�水平�垂直和对角线差�
|
||||
// - �用于边缘检�
|
||||
// - �选归一化输�
|
||||
// 算法: åƒ�ç´ çº§å·®åˆ†è¿�ç®?
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 差分è¿�ç®—ç®—å�
|
||||
/// </summary>
|
||||
public class DifferenceProcessor : ImageProcessorBase
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<DifferenceProcessor>();
|
||||
|
||||
public DifferenceProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("DifferenceProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("DifferenceProcessor_Description");
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Direction", new ProcessorParameter(
|
||||
"Direction",
|
||||
LocalizationHelper.GetString("DifferenceProcessor_Direction"),
|
||||
typeof(string),
|
||||
"Horizontal",
|
||||
null,
|
||||
null,
|
||||
LocalizationHelper.GetString("DifferenceProcessor_Direction_Desc"),
|
||||
new string[] { "Horizontal", "Vertical", "Both" }));
|
||||
|
||||
Parameters.Add("Normalize", new ProcessorParameter(
|
||||
"Normalize",
|
||||
LocalizationHelper.GetString("DifferenceProcessor_Normalize"),
|
||||
typeof(bool),
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
LocalizationHelper.GetString("DifferenceProcessor_Normalize_Desc")));
|
||||
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
string direction = GetParameter<string>("Direction");
|
||||
bool normalize = GetParameter<bool>("Normalize");
|
||||
|
||||
int width = inputImage.Width;
|
||||
int height = inputImage.Height;
|
||||
|
||||
var floatImage = inputImage.Convert<Gray, float>();
|
||||
var result = new Image<Gray, float>(width, height);
|
||||
|
||||
if (direction == "Horizontal")
|
||||
{
|
||||
// 水平差分: I(x+1,y) - I(x,y)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width - 1; x++)
|
||||
{
|
||||
result.Data[y, x, 0] = floatImage.Data[y, x + 1, 0] - floatImage.Data[y, x, 0];
|
||||
}
|
||||
result.Data[y, width - 1, 0] = 0;
|
||||
}
|
||||
}
|
||||
else if (direction == "Vertical")
|
||||
{
|
||||
// 垂直差分: I(x,y+1) - I(x,y)
|
||||
for (int y = 0; y < height - 1; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
result.Data[y, x, 0] = floatImage.Data[y + 1, x, 0] - floatImage.Data[y, x, 0];
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
result.Data[height - 1, x, 0] = 0;
|
||||
}
|
||||
}
|
||||
else // Both
|
||||
{
|
||||
// 梯度幅� sqrt((dx)^2 + (dy)^2)
|
||||
for (int y = 0; y < height - 1; y++)
|
||||
{
|
||||
for (int x = 0; x < width - 1; x++)
|
||||
{
|
||||
float dx = floatImage.Data[y, x + 1, 0] - floatImage.Data[y, x, 0];
|
||||
float dy = floatImage.Data[y + 1, x, 0] - floatImage.Data[y, x, 0];
|
||||
result.Data[y, x, 0] = (float)Math.Sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (normalize)
|
||||
{
|
||||
double minVal = 0, maxVal = 0;
|
||||
Point minLoc = new Point();
|
||||
Point maxLoc = new Point();
|
||||
CvInvoke.MinMaxLoc(result, ref minVal, ref maxVal, ref minLoc, ref maxLoc);
|
||||
|
||||
if (maxVal > minVal)
|
||||
{
|
||||
result = (result - minVal) * (255.0 / (maxVal - minVal));
|
||||
}
|
||||
}
|
||||
|
||||
floatImage.Dispose();
|
||||
_logger.Debug("Process: Direction = {Direction}, Normalize = {Normalize}", direction, normalize);
|
||||
return result.Convert<Gray, byte>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� DivisionProcessor.cs
|
||||
// æ��è¿°: 除法è¿�ç®—ç®—å�,用于图åƒ�归一化处ç�?
|
||||
// 功能:
|
||||
// - 对图åƒ�åƒ�ç´ å€¼è¿›è¡Œé™¤æ³•è¿�ç®?
|
||||
// - 支æŒ�ç¼©æ”¾å› å�调整
|
||||
// - �选归一化到0-255范围
|
||||
// - å¸¸ç”¨äºŽèƒŒæ™¯æ ¡æ£å’Œå›¾åƒ�归一åŒ?
|
||||
// 算法: åƒ�ç´ çº§é™¤æ³•è¿�ç®?
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 除法è¿�ç®—ç®—å�
|
||||
/// </summary>
|
||||
public class DivisionProcessor : ImageProcessorBase
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<DivisionProcessor>();
|
||||
|
||||
public DivisionProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("DivisionProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("DivisionProcessor_Description");
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Divisor", new ProcessorParameter(
|
||||
"Divisor",
|
||||
LocalizationHelper.GetString("DivisionProcessor_Divisor"),
|
||||
typeof(double),
|
||||
2.0,
|
||||
0.01,
|
||||
255.0,
|
||||
LocalizationHelper.GetString("DivisionProcessor_Divisor_Desc")));
|
||||
|
||||
Parameters.Add("Scale", new ProcessorParameter(
|
||||
"Scale",
|
||||
LocalizationHelper.GetString("DivisionProcessor_Scale"),
|
||||
typeof(double),
|
||||
1.0,
|
||||
0.1,
|
||||
10.0,
|
||||
LocalizationHelper.GetString("DivisionProcessor_Scale_Desc")));
|
||||
|
||||
Parameters.Add("Normalize", new ProcessorParameter(
|
||||
"Normalize",
|
||||
LocalizationHelper.GetString("DivisionProcessor_Normalize"),
|
||||
typeof(bool),
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
LocalizationHelper.GetString("DivisionProcessor_Normalize_Desc")));
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
double divisor = GetParameter<double>("Divisor");
|
||||
double scale = GetParameter<double>("Scale");
|
||||
bool normalize = GetParameter<bool>("Normalize");
|
||||
|
||||
var floatImage = inputImage.Convert<Gray, float>();
|
||||
var result = floatImage / divisor * scale;
|
||||
|
||||
if (normalize)
|
||||
{
|
||||
double minVal = 0, maxVal = 0;
|
||||
Point minLoc = new Point();
|
||||
Point maxLoc = new Point();
|
||||
CvInvoke.MinMaxLoc(result, ref minVal, ref maxVal, ref minLoc, ref maxLoc);
|
||||
|
||||
if (maxVal > minVal)
|
||||
{
|
||||
result = (result - minVal) * (255.0 / (maxVal - minVal));
|
||||
}
|
||||
}
|
||||
_logger.Debug("Process:Divisor = {0}, Scale = {1}, Normalize = {2}", divisor, scale, normalize);
|
||||
return result.Convert<Gray, byte>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� IntegralProcessor.cs
|
||||
// æ��è¿°: 积分è¿�ç®—ç®—å�,计算积分图åƒ?
|
||||
// 功能:
|
||||
// - 计算积分图åƒ�ï¼ˆç´¯åŠ å’Œï¼?
|
||||
// - 用于快速区域求�
|
||||
// - 支�归一化输�
|
||||
// 算法: 积分图�算法
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 积分è¿�ç®—ç®—å�
|
||||
/// </summary>
|
||||
public class IntegralProcessor : ImageProcessorBase
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<IntegralProcessor>();
|
||||
|
||||
public IntegralProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("IntegralProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("IntegralProcessor_Description");
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Normalize", new ProcessorParameter(
|
||||
"Normalize",
|
||||
LocalizationHelper.GetString("IntegralProcessor_Normalize"),
|
||||
typeof(bool),
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
LocalizationHelper.GetString("IntegralProcessor_Normalize_Desc")));
|
||||
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
bool normalize = GetParameter<bool>("Normalize");
|
||||
|
||||
int width = inputImage.Width;
|
||||
int height = inputImage.Height;
|
||||
|
||||
// 使用double类型��溢出
|
||||
var integralImage = new Image<Gray, double>(width, height);
|
||||
|
||||
// 计算积分图�
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
double sum = inputImage.Data[y, x, 0];
|
||||
|
||||
if (x > 0)
|
||||
sum += integralImage.Data[y, x - 1, 0];
|
||||
if (y > 0)
|
||||
sum += integralImage.Data[y - 1, x, 0];
|
||||
if (x > 0 && y > 0)
|
||||
sum -= integralImage.Data[y - 1, x - 1, 0];
|
||||
|
||||
integralImage.Data[y, x, 0] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
var result = integralImage.Convert<Gray, float>();
|
||||
|
||||
if (normalize)
|
||||
{
|
||||
double minVal = 0, maxVal = 0;
|
||||
Point minLoc = new Point();
|
||||
Point maxLoc = new Point();
|
||||
CvInvoke.MinMaxLoc(result, ref minVal, ref maxVal, ref minLoc, ref maxLoc);
|
||||
|
||||
if (maxVal > minVal)
|
||||
{
|
||||
result = (result - minVal) * (255.0 / (maxVal - minVal));
|
||||
}
|
||||
}
|
||||
|
||||
integralImage.Dispose();
|
||||
_logger.Debug("Process: Normalize = {Normalize}", normalize);
|
||||
return result.Convert<Gray, byte>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� MultiplicationProcessor.cs
|
||||
// æ��è¿°: 乘法è¿�ç®—ç®—å�,用于图åƒ�增å¼?
|
||||
// 功能:
|
||||
// - 对图åƒ�åƒ�ç´ å€¼è¿›è¡Œä¹˜æ³•è¿�ç®?
|
||||
// - 支�增益调整
|
||||
// - �选归一化输�
|
||||
// - 常用于图�增强和对比度调�
|
||||
// 算法: åƒ�ç´ çº§ä¹˜æ³•è¿�ç®?
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 乘法è¿�ç®—ç®—å�
|
||||
/// </summary>
|
||||
public class MultiplicationProcessor : ImageProcessorBase
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<MultiplicationProcessor>();
|
||||
|
||||
public MultiplicationProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("MultiplicationProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("MultiplicationProcessor_Description");
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Multiplier", new ProcessorParameter(
|
||||
"Multiplier",
|
||||
LocalizationHelper.GetString("MultiplicationProcessor_Multiplier"),
|
||||
typeof(double),
|
||||
2.0,
|
||||
0.1,
|
||||
10.0,
|
||||
LocalizationHelper.GetString("MultiplicationProcessor_Multiplier_Desc")));
|
||||
|
||||
Parameters.Add("Normalize", new ProcessorParameter(
|
||||
"Normalize",
|
||||
LocalizationHelper.GetString("MultiplicationProcessor_Normalize"),
|
||||
typeof(bool),
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
LocalizationHelper.GetString("MultiplicationProcessor_Normalize_Desc")));
|
||||
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
double multiplier = GetParameter<double>("Multiplier");
|
||||
bool normalize = GetParameter<bool>("Normalize");
|
||||
|
||||
var floatImage = inputImage.Convert<Gray, float>();
|
||||
var result = floatImage * multiplier;
|
||||
|
||||
if (normalize)
|
||||
{
|
||||
double minVal = 0, maxVal = 0;
|
||||
Point minLoc = new Point();
|
||||
Point maxLoc = new Point();
|
||||
CvInvoke.MinMaxLoc(result, ref minVal, ref maxVal, ref minLoc, ref maxLoc);
|
||||
|
||||
if (maxVal > minVal)
|
||||
{
|
||||
result = (result - minVal) * (255.0 / (maxVal - minVal));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ä¸�归一化时,直接截æ–到0-255范围
|
||||
result = result.ThresholdBinary(new Gray(255), new Gray(255));
|
||||
}
|
||||
|
||||
floatImage.Dispose();
|
||||
_logger.Debug("Process: Multiplier = {Multiplier}, Normalize = {Normalize}", multiplier, normalize);
|
||||
return result.Convert<Gray, byte>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� OrProcessor.cs
|
||||
// æ��è¿°: 或è¿�ç®—ç®—å�,用于图åƒ�逻辑è¿�ç®—
|
||||
// 功能:
|
||||
// - 对图�进行按�或�算
|
||||
// - 支�与固定值或�算
|
||||
// - å�¯ç”¨äºŽå›¾åƒ�å�ˆå¹¶å’ŒæŽ©ç �æ“�作
|
||||
// 算法: åƒ�ç´ çº§æŒ‰ä½�或è¿�ç®—
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 或è¿�ç®—ç®—å?
|
||||
/// </summary>
|
||||
public class OrProcessor : ImageProcessorBase
|
||||
{
|
||||
private static readonly ILogger _logger = Log.ForContext<OrProcessor>();
|
||||
|
||||
public OrProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("OrProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("OrProcessor_Description");
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Value", new ProcessorParameter(
|
||||
"Value",
|
||||
LocalizationHelper.GetString("OrProcessor_Value"),
|
||||
typeof(int),
|
||||
0,
|
||||
0,
|
||||
255,
|
||||
LocalizationHelper.GetString("OrProcessor_Value_Desc")));
|
||||
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
int value = GetParameter<int>("Value");
|
||||
|
||||
var result = inputImage.Clone();
|
||||
|
||||
// 对æ¯�个åƒ�ç´ è¿›è¡ŒæŒ‰ä½�或è¿�ç®—
|
||||
for (int y = 0; y < inputImage.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < inputImage.Width; x++)
|
||||
{
|
||||
result.Data[y, x, 0] = (byte)(inputImage.Data[y, x, 0] | value);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Debug("Process: Value = {Value}", value);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user