Files
XplorePlane/XP.ImageProcessing.Processors/图像变换/GrayscaleProcessor.cs
T
2026-04-13 14:36:18 +08:00

80 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================================
// Copyright 穢 2026 Hexagon Technology Center GmbH. All Rights Reserved.
// ? GrayscaleProcessor.cs
// 讛膩: 啣漲曇蓮摮琜脣㦛讛蓮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>
/// 啣漲曇蓮摮?
/// </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;
}
}