图像处理-05-浮雕效果处理

浮雕效果处理

浮雕效果:是将图像的变化部分突出的表现出来,而相通的颜色部分则被淡化掉,使图像出现纵深感,从而达到浮雕的效果。

采用的算法是:将要处理的像素与处于同一对角线上的另一个像素做差值,然后加上128,大于255就等于255,小于0就等于0,其他的不做处理

        public Bitmap Relife(Image image)
        {
            int width = image.Width;
            int height = image.Height;

            Bitmap temp = new Bitmap( width, height );
            Bitmap bitmap=(Bitmap)image;
            Color pixel1, pixel2;
            int r, g, b;

            for (int x = 0; x < width - 1; x++)
            {
                for (int y = 0; y < height - 1; y++)
                {
                    pixel1 = bitmap.GetPixel( x, y );
                    pixel2 = bitmap.GetPixel( x + 1, y + 1 );

                    r = Judge( pixel1.R - pixel2.R + 128 );
                    g = Judge( pixel1.G - pixel2.G + 128 );
                    b = Judge( pixel1.B - pixel2.B + 128 );

                    temp.SetPixel( x, y, Color.FromArgb( r, g, b ) );
                }
            }
            return temp;
        }

        public int Judge(int number)
        {
            if (number > 255)
            {
                return 255;
            }
            if (number < 0)
            {
                return 0;
            }
            else
            {
                return number;
            }
        }

原文地址:https://www.cnblogs.com/chenyongblog/p/3405552.html