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


    图像的轮廓提取-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;
            }

     

  • 相关阅读:
    InstallShield自定义对话框模板代码(转)
    破解汇编知识(转)
    Openrowset数据库远程操作
    SQL类似sleep延时语句
    C#结束线程
    JavaScript中相应ActiveX事件
    Visual C# .NET 命令行编辑器
    AfxBeginThread
    atoi,atol,strtod,strtol,strtoul类型转换(转)
    SQLServer PadLeft,PadRight
  • 原文地址:https://www.cnblogs.com/chenyongblog/p/3407426.html
Copyright © 2020-2023  润新知