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

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



[函数名称]

  红眼去除     RedeyeRemoveProcess(WriteableBitmap src)

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

        /// <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;
            }
        }

[图像效果]

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

上一篇:《无人机DIY》——2.4 Vessels


下一篇:黑客:iPhone的这些脑残功能逼我去越狱 苹果:乖,招安是我强项!