Edge Extraction (subpixel Precise)

Basic Concept
 
 
Extended Concept
 
 
Extract Edges or Lines
 
HALCON offers various operators for the subpixel-accurate extraction of contours. The standard oper-
ator is based on the first derivative. It takes the image as input and returns the XLD contours. When
using the second derivatives, first a Laplace operator must be executed before the contours along the
zero crossings can be extracted. Besides the gray-value-based methods, HALCON provides the latest
technology for the extraction of color edges.

Besides the extraction of edges, HALCON provides operators for the extraction of lines. In other systems
lines are also called ridges. In contrast to edges, a line consists of two gray value transitions. Thus, a line
can be considered as two parallel edges
 
HALCON 为亚像素轮廓提取提供了多种运算。
标准的运算是基于一阶导数,输入一幅图像输出一个XLD 轮廓。
当用二阶导数是,拉普拉斯运算。
除此之外,HALCON提供最先进的 提取颜色边缘。
 
最常用的提取边缘轮廓的操作是 edges_sub_pix ,  你可以通过 filter 参数选择不同的滤波操作;
常用的值 'canny'(基于高斯卷积)    ' lanesr2'
‘lanser2’的优点 当用大的平滑的时候,处理时间上没有增加
更快的一个参数是 ‘sobel_fast’,这个图片无噪声用。
 
zero_crossing_sub_pix 可以结合 像 derivate_gauss 参数为 ’laplace’. 使用 laplace 主要用在医学领域
 
最普遍的 线条提取运算是 lines_gauss.和lines_facet 相比更robust更灵活
提取线条的宽度 通过sigma 参数指定 对于很宽的线条我们可以通过 zoom_image_factor 减少运算时间
像提取边缘一样,halcon同样支持 lines_color
 
 
Determine Contour Attributes

The edge and line extraction operators not only provide the XLD contours but also so-called attributes.
Attributes are numerical values; they are associated either with each control point of the contour
(called contour attribute) or with each contour as a whole (global contour attribute). The operators
get_contour_attrib_xld and get_contour_global_attrib_xld enable you to access these val-
ues by specifying the attribute name.
The attribute values are returned as tuples of numbers. Typical attributes for edges are, e.g., the edge am-
plitude and direction. For lines a typical attribute is the line width. The available attributes can be queried
for a given contour with query_contour_attribs_xld and query_contour_global_attribs_xld.
 
 
例子 检测汽车轮子的钻孔Example: solution_guide/basics/rim_simple.hdev
图1

***************************************************
* 1. 二值化 得到包含钻孔的区域(该区域不只含钻孔还有很多其他)
* 2. 用特征直方图 根据 area circularity  得到只含钻孔的区域
* 3.对该区域做boundary 操作 消除内部 只留边缘
* 4.对边缘做膨化
* 5.获取边缘区域的图像 做边缘检测得到边缘轮廓
* 6.fit_ellipse_contour_xld 对轮廓做椭圆适配操作,得到 钻孔的属性特征(因为得到的钻孔轮廓可能不圆,当然也可以用 圆适配替代椭圆适配)
* 7.gen_ellipse_contour_xld生成钻孔边缘
* 关于XLD的知识点后面章节介绍
**************************************************
dev_update_window('off')
dev_update_pc('off')
dev_update_var('off')

read_image(Image,'rim')
get_image_size(Image,Width,Height)

dev_close_window()
dev_open_window(0,0,Width,Height,'black',WindowHandle)

threshold (Image, Dark, 3, 128)

connection(Dark,DarkRegions)

select_shape (DarkRegions, Circles, ['area','circularity'], 'and', [50,0.85], [9999,1])

* 作用如图1所示
boundary(Circles,RegionBorder,'inner')

dilation_circle(RegionBorder,RegionDiation,6.5)

union1(RegionDiation,ROIEdges)

reduce_domain(Image,ROIEdges,ImageROI)

edges_sub_pix(ImageROI,Edges,'lanser2',0.3,10,30)

fit_ellipse_contour_xld (Edges, 'fhuber', -1, 0, 0, 200, 3, 2, Row, Column, Phi, Ra, Rb, StartPhi, EndPhi, PointOrder)

NumHoles :=|Ra|

*gen_tuple_const(NumHoles,'positive') 生成一个const 数组
gen_ellipse_contour_xld (ContEllipse, Row, Column, Phi, Ra, Rb, StartPhi, \
                         EndPhi,gen_tuple_const(NumHoles,'positive'), 1.5)
for i := 0 to NumHoles-1 by 1
    sinPhi := sin(Phi[i])
    cosPhi := cos(Phi[i])
    disp_arrow (WindowHandle, Row[i], Column[i], Row[i] - sinPhi*Ra[i], Column[i] + cosPhi*Ra[i], 1)
    disp_arrow (WindowHandle, Row[i], Column[i], Row[i] - cosPhi*Rb[i], Column[i] - sinPhi*Rb[i], 1)
    disp_arrow (WindowHandle, Row[i], Column[i], Row[i] + sinPhi*Ra[i], Column[i] - cosPhi*Ra[i], 1)
    disp_arrow (WindowHandle, Row[i], Column[i], Row[i] + cosPhi*Rb[i], Column[i] + sinPhi*Rb[i], 1)
    set_tposition (WindowHandle, Row[i] - Rb[i] - 50, Column[i] - 85)
    write_string (WindowHandle, 'D1=' + 2*Ra[i])
    set_tposition (WindowHandle, Row[i] - Rb[i] - 30, Column[i] - 85)
    write_string (WindowHandle, 'D2=' + 2*Rb[i])
endfor
 
 
 
例子 提取心脏血管 -- X光图像
Example: hdevelop/Filters/Lines/lines_gauss.hdev
 
图1
 
图2
 
*********************************************************
*    lines_gauss(Image : Lines : Sigma, Low, High,
*                LightDark,  *提取的是 dark 还是light
*                 ExtractWidth,  *是否提取线宽
*                 LineModel,  *'none', 'bar-shaped', 'parabolic', 'gaussian'  本例中用到'parabolic'(抛物线)
*                CompleteJunctions : )  * 是否提取交叉点 如图2的交叉点
*
*
*     sigma -- 如果太小 则血管提取的将会比较窄
*    Low, High, 用于消除一些无关紧要的线条 如图1
*
*  思路:用lines_gauss 提取血管中心线条,get_contour_xld(Line,Row,Col) 得到线条的点坐标
*  get_contour_attrib_xld 获取线条属性
*  disp_polygon 显示血管轮廓
*
*  threshold_sub_pix 在对比明显的情况下使用
*********************************************************
 
dev_close_window()
read_image (Angio, 'angio-part')
get_image_size(Angio,Width,Height)
dev_open_window (0, 0, Width,Height, 'black', WindowID)
dev_display(Angio)
lines_gauss (Angio, Lines, 2, 0, 1, 'dark', 'true', 'parabolic', 'true')

count_obj(Lines,Number)

for I :=1 to Number by 1
    select_obj(Lines,Line,I)
    get_contour_xld(Line,Row,Col)
    get_contour_attrib_xld(Line,'angle',Angle)
    get_contour_attrib_xld(Line,'width_left',WidthL)
    get_contour_attrib_xld(Line,'width_right',WidthR)
    RowR := Row+cos(Angle)*WidthR*sqrt(0.75)
    ColR := Col+sin(Angle)*WidthR*sqrt(0.75)
    RowL := Row-cos(Angle)*WidthL*sqrt(0.75)
    ColL := Col-sin(Angle)*WidthL*sqrt(0.75)
    dev_set_color ('red')
    dev_display (Line)
    dev_set_color ('green')
    disp_polygon (WindowID, RowL, ColL)
    disp_polygon (WindowID, RowR, ColR)
endfor
 
 
Alternatives to Edge Extraction (Subpixel-Precise)

Subpixel Thresholding
Besides the subpixel-accurate edge and line extractors, HALCON provides a subpixel-accurate thresh-
old operator called threshold_sub_pix. If the illumination conditions are stable, this can be a fast
alternative.
Subpixel Point Extraction
In addition to the contour-based subpixel-accurate data, HALCON offers subpixel-accurate point opera-
tors for various applications. In the reference manual, these operators can be found in the chapter “Filters
. Points”
 
 
 
 





posted @ 2011-12-28 14:59  小马_xiaoLV2  阅读(3738)  评论(0编辑  收藏  举报