Win8 Metro(C#)数字图像处理--2.47人脸红眼去除算法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Trent1985/article/details/45095905


[函数名称]

  红眼去除     RedeyeRemoveProcess(WriteableBitmap src)

        /// <summary>
        /// Redeye remove Process.
        /// </summary>
        /// <param name="src">The source image.</param>
        /// <returns></returns>
        public static WriteableBitmap RedeyeRemoveProcess(WriteableBitmap src)////红眼去除
        {
            if (src != null)
            {
                int w = src.PixelWidth;
                int h = src.PixelHeight;
                WriteableBitmap srcImage = new WriteableBitmap(w, h);
                byte[] temp = src.PixelBuffer.ToArray();
                byte[] tempMask = (byte[])temp.Clone();
                int r, g, b;
                int Rc, Gc, Bc;
                for (int i = 0; i < temp.Length; i += 4)
                {
                    b = tempMask[i];
                    g = tempMask[i + 1];
                    r = tempMask[i + 2];
                    if (r > (int)(g + b))//这里 只是简单的判断一下红眼像素只为说明红眼去除算法,实际上要使用一定的红眼判断算法决策
                    {
                        Rc = (int)((g + b) / 2);
                        Gc = (int)((g + Rc) / 2);
                        Bc = (int)((b + Rc) / 2);
                        temp[i] = (byte)Bc;
                        temp[i + 1] = (byte)Gc;
                        temp[i + 2] = (byte)Rc;
                    }
                }
                Stream sTemp = srcImage.PixelBuffer.AsStream();
                sTemp.Seek(0, SeekOrigin.Begin);
                sTemp.Write(temp, 0, w * 4 * h);
                return srcImage;
            }
            else
            {
                return null;
            }
        }

[图像效果]


阅读更多

扫码向博主提问

Trent1985

博客专家

人像美颜美妆滤镜
  • 擅长领域:
  • 人像美颜算法
  • 人像美妆算法
  • 照片滤镜
  • 疯狂换脸相关
  • AI美颜
去开通我的Chat快问
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页