Win8Metro(C#)数字图像处理--2.33图像非线性变换



[函数名称]

图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src,int k ) 

Win8Metro(C#)数字图像处理--2.33图像非线性变换_第1张图片

[函数代码]
        /// 
        /// Nonlinear transform process.
        /// 
        /// The source image.
        /// Param to adjust nonlinear transform, from 0 to 255.
        /// 
        public static WriteableBitmap NonlinearTransformProcess(WriteableBitmap src,int k )////37
        {
            if (src != null)
            {
                int w = src.PixelWidth;
                int h = src.PixelHeight;
                WriteableBitmap linearImage = new WriteableBitmap(w, h);
                byte[] temp = src.PixelBuffer.ToArray();
                int r = 0, g = 0, b = 0;
                for (int i = 0; i < temp.Length; i += 4)
                {
                    b = (int)(k * Math.Log10(1 + temp[i]));
                    g = (int)(k * Math.Log10(1 + temp[i + 1]));
                    r = (int)(k * Math.Log10(1 + temp[i + 2]));
                    temp[i] = (byte)(b > 0 ? (b < 255 ? b : 255) : 0);
                    temp[i + 1] = (byte)(g > 0 ? (g < 255 ? g : 255) : 0);
                    temp[i + 2] = (byte)(r > 0 ? (r < 255 ? r : 255) : 0);              
                }
                Stream sTemp = linearImage.PixelBuffer.AsStream();
                sTemp.Seek(0, SeekOrigin.Begin);
                sTemp.Write(temp, 0, w * 4 * h);
                return linearImage;
            }
            else
            {
                return null;
            }   
        }
Win8Metro(C#)数字图像处理--2.33图像非线性变换_第2张图片

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