zoukankan      html  css  js  c++  java
  • 图像处理-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;
            }

     

  • 相关阅读:
    又快又准的sql瓶颈诊断方法
    Qps从300到1500的优化过程
    Mysql性能优化全揭秘-庖丁解牛
    java学习笔记16-抽象类
    java学习笔记15-封装
    java学习笔记14-多态
    java学习笔记13-重写与重载
    Git学习笔记08-远程仓库
    Python3+Appium学习笔记09-元素定位android_uiautomator
    Python3+Appium学习笔记08-元素定位
  • 原文地址:https://www.cnblogs.com/chenyongblog/p/3407426.html
Copyright © 2011-2022 走看看