Search code examples
c#windows-phone-8image-processingnokia-imaging-sdklumia-imaging-sdk

Red Eye reduction with nokia imaging SDK


I try to implement red eye reduction algorithm with Nokia Imaging SDK. I've wroten control to pick eye-circles so I dont need segmentation/face detection phase (i have points list within a circle) - I implemented it this way:

 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++;
        });
    }

where AlphaBitMask = 0xFF000000, RedBitMask = 0x00FF0000, GreenBitMask = 0x0000FF00, BlueBitMask = 0x000000FF

However I get weird results:

Results in left circle

The question is: does Nokia Imaging SDK uses some alpha blending? What should I do with alpha channel ? Another important question - does anyone have dealt with CustomFilterBase? How can I process only list of points (so I could use _selectedRegionProvider.GetAllSelectedPoints() which returns IEnumerable of Point) because from what I've seen OnProcess is divided into multiple parts (so I can't access all pixels in single OnProcess).


Solution

  • Good news! There is a RedEyeRemovalFilter in the newly released Lumia Imaging SDK 2.0. You can upgrade through NuGet, and visit http://dev.windows.com/en-us/featured/lumia for more information.

    Note that the documentation on MSDN is quite broken currently, and not fully up to date. Hopefully this will be fixed soon.

    For reference docs, the chm file in the NuGet package is current and clean.