图像基本变换---图像曝光+反相算法

[算法说明]

设置一阈值T属于[0, 255],对于灰度值小于该阈值的像素,将其RGB值按公式2-(40)取逆,从而使图像产生正片和负片混合的效果。

[函数代码]

        /// 

        /// Exposure process.

        /// 

        /// Source image.

        /// To adjust exposure lavel, from 0 to 255.

        /// 

        public static WriteableBitmap ExposureProcess(WriteableBitmap src,int exposureValue)////35图像曝光

        {

            if (src != null)

            {

                int w = src.PixelWidth;

                int h = src.PixelHeight;

                WriteableBitmap exposureImage = new WriteableBitmap(w, h);

                int r=0,g=0,b=0;

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

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

                {

                    byte tempByte = (byte)((int)(temp[i] * 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299));

                    b = temp[i];

                    g = temp[i + 1];

                    r = temp[i + 2];

                    if (tempByte < 128)

                    {

                        temp[i] = (byte)(255 - b);

                        temp[i + 1] = (byte)(255 - g);

                        temp[i + 2] = (byte)(255 - r);

                    }

                }

                Stream sTemp = exposureImage.PixelBuffer.AsStream();

                sTemp.Seek(0, SeekOrigin.Begin);

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

                return exposureImage;

            }

            else

            {

                return null;

            }         

        }

[图像效果]

图像基本变换---图像曝光+反相算法_第1张图片

Fig.1原图                     Fig.2效果图(exposureValue=128)


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

你可能感兴趣的:(图像基础)