规范类名及命名空间名称
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// ============================================================================
|
||||
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||||
// 文件� GammaProcessor.cs
|
||||
// æ��è¿°: Gammaæ ¡æ£ç®—å�,用于调整图åƒ�亮度和对比åº?
|
||||
// 功能:
|
||||
// - Gammaé�žçº¿æ€§æ ¡æ?
|
||||
// - 增益调整
|
||||
// - 使用查找表(LUTï¼‰åŠ é€Ÿå¤„ç�?
|
||||
// - 适用于图�显示和亮度调整
|
||||
// 算法: Gammaæ ¡æ£å…¬å¼� output = (input^(1/gamma)) * gain
|
||||
// 作� �伟 wei.lw.li@hexagon.com
|
||||
// ============================================================================
|
||||
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using Serilog;
|
||||
using XP.ImageProcessing.Core;
|
||||
|
||||
namespace XP.ImageProcessing.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// Gammaæ ¡æ£ç®—å�
|
||||
/// </summary>
|
||||
public class GammaProcessor : ImageProcessorBase
|
||||
{
|
||||
private byte[] _lookupTable;
|
||||
private static readonly ILogger _logger = Log.ForContext<GammaProcessor>();
|
||||
|
||||
public GammaProcessor()
|
||||
{
|
||||
Name = LocalizationHelper.GetString("GammaProcessor_Name");
|
||||
Description = LocalizationHelper.GetString("GammaProcessor_Description");
|
||||
_lookupTable = new byte[256];
|
||||
}
|
||||
|
||||
protected override void InitializeParameters()
|
||||
{
|
||||
Parameters.Add("Gamma", new ProcessorParameter(
|
||||
"Gamma",
|
||||
LocalizationHelper.GetString("GammaProcessor_Gamma"),
|
||||
typeof(double),
|
||||
1.0,
|
||||
0.1,
|
||||
5.0,
|
||||
LocalizationHelper.GetString("GammaProcessor_Gamma_Desc")));
|
||||
|
||||
Parameters.Add("Gain", new ProcessorParameter(
|
||||
"Gain",
|
||||
LocalizationHelper.GetString("GammaProcessor_Gain"),
|
||||
typeof(double),
|
||||
1.0,
|
||||
0.1,
|
||||
3.0,
|
||||
LocalizationHelper.GetString("GammaProcessor_Gain_Desc")));
|
||||
_logger.Debug("InitializeParameters");
|
||||
}
|
||||
|
||||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||||
{
|
||||
double gamma = GetParameter<double>("Gamma");
|
||||
double gain = GetParameter<double>("Gain");
|
||||
|
||||
BuildLookupTable(gamma, gain);
|
||||
|
||||
var result = inputImage.Clone();
|
||||
ApplyLookupTable(result);
|
||||
_logger.Debug("Process:Gamma = {0}, Gain = {1}", gamma, gain);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void BuildLookupTable(double gamma, double gain)
|
||||
{
|
||||
double invGamma = 1.0 / gamma;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
double normalized = i / 255.0;
|
||||
double corrected = Math.Pow(normalized, invGamma) * gain;
|
||||
int value = (int)(corrected * 255.0);
|
||||
|
||||
_lookupTable[i] = (byte)Math.Max(0, Math.Min(255, value));
|
||||
}
|
||||
_logger.Debug("Gamma and gain values recorded: gamma = {Gamma}, gain = {Gain}", gamma, gain);
|
||||
}
|
||||
|
||||
private void ApplyLookupTable(Image<Gray, byte> image)
|
||||
{
|
||||
int width = image.Width;
|
||||
int height = image.Height;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
byte pixelValue = image.Data[y, x, 0];
|
||||
image.Data[y, x, 0] = _lookupTable[pixelValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user