80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
// ============================================================================
|
||
// Copyright 穢 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
||
// ��辣�? GrayscaleProcessor.cs
|
||
// �讛膩: �啣漲�曇蓮�Y�摮琜��其�撠�蔗�脣㦛�讛蓮�V蛹�啣漲�曉�
|
||
// �蠘�:
|
||
// - ����啣漲頧祆揢嚗����像���
|
||
// - 撟喳��潭�
|
||
// - ��憭批�潭�
|
||
// - ��撠誩�潭�
|
||
// 蝞埈�: �䭾�撟喳�瘜?Gray = 0.299*R + 0.587*G + 0.114*B
|
||
// 雿𡏭�? �𦒘� wei.lw.li@hexagon.com
|
||
// ============================================================================
|
||
|
||
using Emgu.CV;
|
||
using Emgu.CV.Structure;
|
||
using Serilog;
|
||
using XP.ImageProcessing.Core;
|
||
|
||
namespace XP.ImageProcessing.Processors;
|
||
|
||
/// <summary>
|
||
/// �啣漲�曇蓮�Y�摮?
|
||
/// </summary>
|
||
public class GrayscaleProcessor : ImageProcessorBase
|
||
{
|
||
private static readonly ILogger _logger = Log.ForContext<GrayscaleProcessor>();
|
||
|
||
public GrayscaleProcessor()
|
||
{
|
||
Name = LocalizationHelper.GetString("GrayscaleProcessor_Name");
|
||
Description = LocalizationHelper.GetString("GrayscaleProcessor_Description");
|
||
}
|
||
|
||
protected override void InitializeParameters()
|
||
{
|
||
Parameters.Add("Method", new ProcessorParameter(
|
||
"Method",
|
||
LocalizationHelper.GetString("GrayscaleProcessor_Method"),
|
||
typeof(string),
|
||
"Weighted",
|
||
null,
|
||
null,
|
||
LocalizationHelper.GetString("GrayscaleProcessor_Method_Desc"),
|
||
new string[] { "Weighted", "Average", "Max", "Min" }));
|
||
_logger.Debug("InitializeParameters");
|
||
}
|
||
|
||
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
||
{
|
||
string method = GetParameter<string>("Method");
|
||
|
||
// 憒��颲枏�撌脩��舐�摨血㦛嚗峕覔�格䲮瘜閗�銵���?
|
||
var result = inputImage.Clone();
|
||
|
||
switch (method)
|
||
{
|
||
case "Average":
|
||
// 撖嫣�撌脩��舐�摨衣��曉�嚗�像���潭�銝齿㺿�睃㦛�?
|
||
break;
|
||
|
||
case "Max":
|
||
// 憓𧼮撩鈭桀漲
|
||
result = result * 1.2;
|
||
break;
|
||
|
||
case "Min":
|
||
// �滢�鈭桀漲
|
||
result = result * 0.8;
|
||
break;
|
||
|
||
case "Weighted":
|
||
default:
|
||
// 靽脲���甅
|
||
break;
|
||
}
|
||
|
||
_logger.Debug("Process: Method = {Method}", method);
|
||
return result;
|
||
}
|
||
} |