第三课: 图像的 BLOB 分析处理流程(clip_region_rel,edges_sub_pix,segment_contours_xld等)---Circles.hdev

 所用到的算子:

1、boundary(Region : RegionBorder : BoundaryType : )  *提取区域的边界,实质是像素

      boundary (Region, RegionBorder, 'inner')

2、clip_region_rel(Region : RegionClipped : Top, Bottom, Left, Right : )*通过区域的最小外接矩形,从矩形的                                 Top,Bottom,Left,Right四个方向裁剪区域,得到所需要的区域

                  

       如果需要提取某区域中的一部分区域可以考虑使用该算子,如下图一到图二 :

                                                     

                                                                                                              图一

                                                              

                                                                                                            图二 

 3、    edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : )*提取亚像素精密边缘轮廓

           参数: Low和High

           使用灰度直方图计算两个阀值,凡是像素灰度值大于高阀值的一定是轮廓; 凡是小于低阀值的一定不是轮廓;

            如果检测像素灰度值大于低阀值但又小于高阀值,那就要看这个像素的邻接像素中有没有超过高阀值的边缘像素:如果有的话那么它就是轮廓边缘了,否则他就不是轮廓边缘;

            alpha:

            指定值越小,平滑越强大,会减少边缘细节。

            Filter :

            Filter  = 'canny'刚好相反,alpha值越大,轮廓细节就越少(可能有一部分轮廓消失)

            如下:                          

            edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)

                                                                                 

4、segment_contours_xld(Contours : ContoursSplit : Mode, SmoothCont, MaxLineDist1, MaxLineDist2 : )

       将亚像素轮廓分割为值线段、圆、或圆弧

       Contours :需要进行分割的轮廓。

       ContoursSplit: 分割后的轮廓tuple。

       Mode:分割轮廓方式

       'lines'(使用直线段分割), 'lines_circles'(使用直线段和圆(弧)分割), 'lines_ellipses'(使用直线段和椭圆弧分割)。

       SmoothCont :轮廓平滑的参数,可以抑制在折线逼近过程中过短的线段,能更加逼近圆和椭圆。
        MaxLineDist1: 值越小,分割得到的线段、圆弧、或椭圆弧就越多

        MaxLineDist2 :值越小,分割得到的线段、圆弧、或椭圆弧就越多

        Remark:

        分割得到的轮廓是直线段、圆(圆弧)或者椭圆弧可以通过分割后轮廓的全局属性'cont_approx’参数的值来判断(参考               get_contour_global_attrib_xld)。

        如果'cont_approx'=-1,这一部分轮廓最适合被拟合为直线段。

        如果'cont_approx'=0,这一部分轮廓最适合被拟合为椭圆弧。

        如果'cont_approx'=1,这一部分轮廓最适合被拟合为圆弧。

5 、get_contour_global_attrib_xld(Contour : : Name : Attrib)

       返回亚像素轮廓的全局属性

       *通过segment_contours_xld算子得到轮廓被分割的部分然后通过get_contour_global_attrib_xld 算子的cont_approx               属性值判断被分割的轮廓部分是直线还是圆弧或椭圆弧

       get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    *判断分割的轮廓是否适合生成圆
     if (Attrib > 0)
        *提取圆弧生成圆的参数
       
fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        *圆弧生成圆
       
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
        dev_display (ContCircle)
    endif

6、 fit_circle_contour_xld,gen_circle_contour_xld

* The edges in the image are segmented into lines and circles.
* For the edges that are part of a circle, the circle parameters
* are estimated and the resulting circle is displayed.
read_image (Image, 'double_circle')
* 
* Init window
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 
*Segment a region containing the edges
*分割包含边的区域
fast_threshold (Image, Region, 0, 120, 7)
*提取区域的内边缘
boundary (Region, RegionBorder, 'inner')
*通过区域的最小外接矩形,从矩形的TOP,Bottom,Left,Right四个方向裁剪区域
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5,5)
*膨胀轮廓区域
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
* 
* In the subdomain of the image containing the edges,
* extract subpixel precise edges.
*提取亚像素精密边缘轮廓
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
*将XLD轮廓分割为线段和圆弧
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
count_obj (ContoursSplit, Number)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
    select_obj (ContoursSplit, ObjectSelected, I)
    *返回亚像素轮廓的全局属性
    *如果Attrib =-1,这一部分轮廓最适合被拟合为直线段。
    *如果Attrib =0,这一部分轮廓最适合被拟合为椭圆弧。
    *如果Attrib =1,这一部分轮廓最适合被拟合为圆弧。

    get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
    * Fit a circle to the line segment that are arcs of a circle
    *判断分割的轮廓是否适合生成圆
    if (Attrib > 0)
        *提取圆弧生成圆的参数
        fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        *圆弧生成圆
        gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
        dev_display (ContCircle)
    endif
endfor
dev_set_colored (12)
dev_set_line_width (3)
dev_display (ContoursSplit)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值