图像处理-07-图像的轮廓提取-Robert算子_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 图像处理-07-图像的轮廓提取-Robert算子

图像处理-07-图像的轮廓提取-Robert算子

 2013/11/4 23:36:00  种花生的读书人  博客园  我要评论(0)
  • 摘要:图像的轮廓提取-Robert算子图像的边缘:周围像素灰度有阶跃变化或“屋顶”变化的那些像素的集合,边缘广泛存在于物体与背景之间、物体与物体之间,基元与基元之间,是图像分割的重要依据。物体的边缘是由灰度不连续性形成的,经典的边缘提取方法是考察图像的每个像素在某个领域内灰度的变化,利用边缘邻近一阶或二阶方向倒数变化规律,用简单的方法检测边缘,这种方法称为边缘检测局部算子。publicBitmapRobert(Imageimage){intwidth=image.Width
  • 标签:图像处理

class="title">图像的轮廓提取-Robert算子

图像的边缘:周围像素灰度有阶跃变化或“屋顶”变化的那些像素的集合,边缘广泛存在于物体与背景之间、物体与物体之间,基元与基元之间,是图像分割的重要依据。

物体的边缘是由灰度不连续性形成的,经典的边缘提取方法是考察图像的每个像素在某个领域内灰度的变化,利用边缘邻近一阶或二阶方向倒数变化规律,用简单的方法检测边缘,这种方法称为边缘检测局部算子。

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

            Bitmap temp=new Bitmap(width,height);
            Bitmap bitmap=(Bitmap)image;

            int x,y,p0,p1,p2,p3,result;
            Color[]pixel=new Color[4];

            for (y = height - 2; y > 0; y--)
            {
                for (x = 0; x < width - 2; x++)
                {
                    pixel[0] = bitmap.GetPixel( x, y );
                    pixel[1] = bitmap.GetPixel(x,y+1);
                    pixel[2] = bitmap.GetPixel( x + 1, y );
                    pixel[3] = bitmap.GetPixel( x + 1, y + 1 );
                    p0 = (int)(0.3 * pixel[0].R + 0.59 * pixel[0].G + 0.11 * pixel[0].B);
                    p1 = (int)(0.3 * pixel[1].R + 0.59 * pixel[1].G + 0.11 * pixel[1].B);
                    p2 = (int)(0.3 * pixel[2].R + 0.59 * pixel[2].G + 0.11 * pixel[2].B);
                    p3 = (int)(0.3 * pixel[3].R + 0.59 * pixel[3].G + 0.11 * pixel[3].B);
                    result = (int)Math.Sqrt( (p0 - p3) * (p0 - p3) + (p1 - p2) * (p1 - p2) );
                    if (result > 255)
                        result = 255;
                    if (result < 0)
                        result = 0;
                    temp.SetPixel( x, y, Color.FromArgb( result, result, result ) );
                }
            }
            return temp;
        }

 

发表评论
用户名: 匿名