规范类名及命名空间名称
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user