图像基础---RGB分量增强效果

RGB分量调整实际上是分别对每个像素的RGB三个分量进行调整,公式如下:

图像基础---RGB分量增强效果_第1张图片

[函数代码]

        /// 

        /// R,G,B value adjusting.

        /// 

        /// The source image.

        /// To judge which one to adjust, R is 3, G is 2, B is 1.

        /// It is a value to adjust the result image.

        /// 

        public static WriteableBitmap RGBAdjustProcess(WriteableBitmap src,int value,int threshould)////41 RGB分量调整

        {

            if (src != null)

            {

                int w = src.PixelWidth;

                int h = src.PixelHeight;

                WriteableBitmap srcImage = new WriteableBitmap(w, h);

                byte[] temp = src.PixelBuffer.ToArray();

                if (value == 1)

                {

                    for (int i = 0; i < temp.Length; i += 4)

                    {

                        temp[i] = (byte)(Math.Max(0, Math.Min((temp[i] + threshould), 255)));

                    }

                }

                if (value == 2)

                {

                    for (int i = 0; i < temp.Length; i += 4)

                    {

                        temp[i + 1] = (byte)(Math.Max(0, Math.Min((temp[i + 1] + threshould), 255)));

                    }

                }

                if (value == 3)

                {

                    for (int i = 0; i < temp.Length; i += 4)

                    {

                        temp[i + 2] = (byte)(Math.Max(0, Math.Min((temp[i + 2] + threshould), 255)));

                    }

                }

                Stream sTemp = srcImage.PixelBuffer.AsStream();

                sTemp.Seek(0, SeekOrigin.Begin);

                sTemp.Write(temp, 0, w * 4 * h);

                return srcImage;

            }

            else

            {

                return null;

            }

        }

[图像效果]

图像基础---RGB分量增强效果_第2张图片

                Fig.1原图             

图像基础---RGB分量增强效果_第3张图片

       Fig.2B分量调整(threshould=255)

图像基础---RGB分量增强效果_第4张图片

      Fig.2G分量调整(threshould=255)      

图像基础---RGB分量增强效果_第5张图片

      Fig.2R分量调整(threshould=255)


demo 下载: http://www.zealfilter.com/forum.php?mod=viewthread&tid=46&extra=page%3D1

你可能感兴趣的:(图像基础---RGB分量增强效果)