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



[函数名称]

  红眼去除     RedeyeRemoveProcess(WriteableBitmap src)

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

        /// 
        /// Redeye remove Process.
        /// 
        /// The source image.
        /// 
        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人脸红眼去除算法_第2张图片

你可能感兴趣的:(Win8,Metro(C#),数字图像处理)