88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
// ============================================================================
|
|
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
|
// 文件名: MultiplicationProcessor.cs
|
|
// 描述: 乘法运算算子,用于图像增强
|
|
// 功能:
|
|
// - 对图像像素值进行乘法运算
|
|
// - 支持增益调整
|
|
// - 可选归一化输出
|
|
// - 常用于图像增强和对比度调整
|
|
// 算法: 像素级乘法运算
|
|
// 作者: 李伟 wei.lw.li@hexagon.com
|
|
// ============================================================================
|
|
|
|
using Emgu.CV;
|
|
using Emgu.CV.Structure;
|
|
using XP.ImageProcessing.Core;
|
|
using Serilog;
|
|
using System.Drawing;
|
|
|
|
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>();
|
|
}
|
|
} |