合并图像处理库,删除图像lib库
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 ImageProcessing.Core;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
|
||||
namespace 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 ImageProcessing.Core;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
|
||||
namespace 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 ImageProcessing.Core;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
|
||||
namespace 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 ImageProcessing.Core;
|
||||
using Serilog;
|
||||
using System.Drawing;
|
||||
|
||||
namespace 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 ImageProcessing.Core;
|
||||
using Serilog;
|
||||
|
||||
namespace 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