我尝试使用 Nokia Imaging SDK 实现红眼消除算法。我已经编写了控制来选择眼圈,所以我不需要分割/面部检测阶段(我在一个圆圈内有点列表) - 我是这样实现的:
protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
{
int currentRow = 0;
targetPixelRegion.ForEachRow((index, width, position) =>
{
for (int x = 0; x < width; ++x)
{
uint currentPixelColor = sourcePixelRegion.ImagePixels[index + x];
if (_selectedRegionProvider.IsPointInSelectedRegion(position.X + x, position.Y + currentRow))
{
uint alphaChannel = (currentPixelColor & AlphaBitMask) >> 24;
uint redChannel = (currentPixelColor & RedBitMask) >> 16;
uint greenChannel = (currentPixelColor & GreenBitMask) >> 8;
uint blueChannel = (currentPixelColor & BlueBitMask);
float greenBlueChannelAvg = (greenChannel + blueChannel)/2.0f;
float redIntensity = (float) (redChannel/greenBlueChannelAvg);
if (redIntensity > 0.5)
redChannel = Math.Min(255, (uint)((greenChannel+blueChannel)/2.0));
currentPixelColor = (alphaChannel << 24) | (redChannel << 16) | (greenChannel << 8) | blueChannel;
}
targetPixelRegion.ImagePixels[index + x] = currentPixelColor;
}
currentRow++;
});
}
,
AlphaBitMask = 0xFF000000
,
RedBitMask = 0x00FF0000
,
GreenBitMask = 0x0000FF00
_
BlueBitMask = 0x000000FF
但是我得到了奇怪的结果:
问题是:Nokia Imaging SDK 是否使用了一些 alpha 混合?我应该如何处理 alpha 通道?另一个重要的问题 - 有人处理过CustomFilterBase
吗?我怎样才能只处理点列表(所以我可以使用_selectedRegionProvider.GetAllSelectedPoints()
它返回 IEnumerable of Point),因为从我所看到OnProcess
的内容分为多个部分(所以我无法访问单个 OnProcess 中的所有像素)。