Halcon-边缘检测算子


边缘检测的定义 :使用数学方法提取图像像元中具有亮度值(灰度)空间方向梯度大的边、线特征的过程。

边缘 是指周围像素灰度有阶跃变化或屋顶等变化的那些像素的集合。图像的边缘对应着图像灰度的不连续性。显然图像的边缘很少是从一个灰度跳到另一个灰度这样的理想状况。真实图像的边缘通常都具有有限的宽度呈现出陡峭的斜坡状。边缘的锐利程度由图像灰度的梯度决定。梯度是指灰度变化的最快的方向和数量。

常见的边缘点有三种 :第一种是阶梯形边缘 (Step-edge), 即从一个灰度到比它高好多的另一个灰度。第二种是屋顶型边缘 (Roof-edge), 它的灰度是慢慢增加到一定程度然后慢慢减小。还有一种是线性边缘 (Line-edge), 它的灰度从一级别跳到另一个灰度级别之后然后回来。

边缘检测的方法主要有以下几种:

第一种检测梯度的最大值。由于边缘发生在图像灰度值变化比较大的地方 , 对应连续情形就是说是函数梯度较大的地方,所以研究比较好的求导算子就成为一种思路。 Roberts 算子、 Prewitt 算子和 Sobel 算子等就是比较简单而常用的例子。还有一种比较直观的方法就是利用当前像素邻域中的一些像素值拟合一个曲面 , 然后求这个连续曲面在当前像素处梯度。从统计角度来说 , 我们可以通过回归分析得到一个曲面 , 然后也可以做类似的处理。

第二种是检测二阶导数的零交叉点。这是因为缘处的梯度取得最大值 ( 正的或者负的 ), 也就是灰度图像的拐点是边缘。从分析学上我们知道 , 拐点处函数的二阶导数是 0 。

第三种,统计型方法。比如说利用假设检验来检测边缘中利用对二阶零交叉点的统计分析得到了图像中各个像素是边缘的概率,并进而得到边缘检测的方案。

以上摘自:https://blog.csdn.net/xinrui_hhuc/article/details/5819057




Filter Image
 
HALCON offers a wide range of edge filters. One of the most popular filters is the Sobel filter. This
is the best of the old-fashioned filters. It combines speed with a reasonable quality. The corresponding
operators are called sobel_amp and sobel_dir.
In contrast, edges_image provides the state of the art of edge filters. This operator is actually more
than just a filter. It includes a thinning of the edges using a non-maximum suppression and a hysteresis
threshold for the selection of significant edge points. It also returns the edge direction and the edge
amplitude very accurately, which is not the case with the Sobel filter. This operator is recommended if
higher quality is more important than a longer execution time. If the images are not noisy or blurred,
you can even combine accuracy and speed by using the mode ’sobel_fast’ inside edges_image. The
corresponding operator to find edges in multi-channel images, e.g., a color image, is edges_color.
 
HALCON 提供广泛的边缘滤波器,最著名的是sobel滤波器,它是老式滤波器中最好的,对应的运算符为sobel_amp  sobel_dir.
edges_image更强大,它不仅仅是滤波器,包括了 thin边缘 二值化选择有效边缘点。返回 the edge direction and the edge
amplitude ,如果图像不是很多噪声且要追求追求高质量推荐使用此运算符。
sobel_fast 结合精度和速度
edges_color 多通道
 
Extract Edges  提取边缘
The easiest way to extract the edges from the edge amplitude image is to apply threshold to select
pixels with a high edge amplitude. The result of this step is a region that contains all edge points. With
skeleton, these edges can be thinned to a width of one pixel. As an advanced version for threshold,
hysteresis_threshold can be used to eliminate insignificant edges. A further advanced option is to
call the operator nonmax_suppression_dir before skeleton, which in difficult cases may result in
more accurate edges. Note that in order to use this operator you must have computed the edge direction
image.
In contrast, the advanced filter edges_image already includes the non-maximum suppression and the
hysteresis threshold. Therefore, in this case a simple threshold suffices to extract edges that are one
pixel wide.
If only the edge points as a region are needed, the operator inspect_shape_model can be used. Here,
all steps including edge filtering, non-maximum suppression, and hysteresis thresholding are performed
in one step with high efficiency.
 
最简单的方法是 对 edge amplitude 图像 应用 二值化 算则高边缘梯度的点。
结果是一个包含所有边缘点的区域,用 skeleton 骨骼化边缘 成1 像素宽度。
更先进的二值化方法hysteresis_threshold 可以去除无关紧要的边缘。
更进一步的操作是在用 skeleton之前 先用一下nonmax_suppression_dir (它也有细化的效果,使用它的前题是 需要 Edge Dirction 图像)
 
相对来说edges_image 包含了上述的操作,因为提取出的边缘是1像素宽度
 
如果边缘点 仅仅是作为 region的话 ,可以用inspect_shape_model ,这个运算符包括
all steps including edge filtering, non-maximum suppression, and hysteresis thresholding are performed
in one step with high efficiency.
 
Process Edge
 
If you want to extract the coordinates of edge segments, split_skeleton_lines is the right choice.
This operator must be called for each connected component (result of connection) and returns all the
control points of the line segments. As an alternative, a Hough transform can be used to obtain the
line segments. Here, the operators hough_lines_dir and hough_lines are available. You can also
convert the edge region into XLD contours by using, e.g., the operator gen_contours_skeleton_xld.
 
The advantage of this approach is the extended set of operators offered for XLD contour processing on
page 81, e.g., for contour segmentation, feature extraction, or approximation.
You can extract the regions enclosed by the edges easily using background_seg. If regions merge
because of gaps in the edges, the operators close_edges or close_edges_length can be used in
advance to close the gaps before regions are extracted. As an alternative, morphological operators like
opening_circle can be applied to the output regions of background_seg. In general, all operators
described for the method Process Regions on page 33 can be applied here as well.

1. sobel_amp ( Image : EdgeAmplitude : FilterType, Size : ) 根据图像的一次导数计算图像的边缘

********************************************
*   sobel_amp(Image : EdgeAmplitude : FilterType, Size : )
*   不能完全排除虚假边缘,检测出的结果容易出现多像素边缘
*   sobel算子由两个卷积核组成
*          a =
 1 2 1
 0 0 0
 -1 -2 -1
 b =
 1 0 -1
 2 0 -2
 1 0 -1
EdgeAmplitude output -- 边缘强度图像
FilterType
         'sum_sqrt'             sqrt(a^2 + b^2) / 4
 'sum_abs' (|a| + |b|) / 4
 'thin_sum_abs' (thin(|a|) + thin(|b|)) / 4
 'thin_max_abs' max(thin(|a|),thin(|b|)) / 4
 'x' b / 4
 'y' a / 4
 
*************************************************

dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 768, 575, 'black', WindowID)
MinSize := 30
get_system ('init_new_image', Information)
set_system ('init_new_image', 'false')
dev_set_line_width (3)
dev_set_color ('green')
stop ()
for i := 0 to 28 by 1
    read_image (ActualImage, 'autobahn/scene_'+(i$'02'))    
    gen_rectangle1 (Rectangle, 130, 0, 512, 512)
    reduce_domain (ActualImage, Rectangle, ReduceImage)
    sobel_amp (ReduceImage, Amp, 'sum_abs', 3)
    threshold (Amp, Points, 20, 255)
    dilation_rectangle1 (Points, RegionDilation, MinSize, MinSize)
    reduce_domain (ActualImage, RegionDilation, StripGray)
    threshold (StripGray, Strip, 190, 255)
    fill_up (Strip, RegionFillUp)
    dev_display (ActualImage)
    dev_display (RegionFillUp)
*     stop()
endfor
dev_set_line_width (1)
dev_update_window ('on')
set_system ('init_new_image', Information)


2.close_edges ( Edges, EdgeImage : RegionResult : MinAmplitude : )

read_image (Image, 'fabrik')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
sobel_amp (Image, EdgeAmplitude, 'thin_sum_abs', 3)
threshold (EdgeAmplitude, Edges, 30, 255)
close_edges (Edges, EdgeAmplitude, EdgesExtended, 15)
dev_set_color ('green')
dev_display (EdgesExtended)
dev_set_color ('red')
dev_display (Edges)

close_edges_length ( Edges, Gradient : ClosedEdges : MinAmplitude, MaxGapLength : ) 使用边缘高度图像关闭边缘间隙。输出的区域包含杯关闭的区域。(感觉是对边缘的扩充)

derivate_gauss ( Image : DerivGauss : Sigma, Component : )

watersheds ( Image : Basins, Watersheds : : ) 从图像中提取风水岭。

zero_crossing ( Image : RegionCrossing : : ) 零交点(二次导数)

diff_of_gauss ( Image : DiffOfGauss : Sigma, SigFactor : ) 近似日志算子( 拉普拉斯高斯) 。

laplace_of_gauss ( Image : ImageLaplace : Sigma : ) 拉普拉斯高斯

edges_color_sub_pix ( Image : Edges : Filter, Alpha, Low, High : ) 精确的亚像素边缘提取(彩色图像)

edges_sub_pix ( Image : Edges : Filter, Alpha, Low, High : ) 精确边缘提取的亚像素(灰度图像)

edges_color ( Image : ImaAmp, ImaDir : Filter, Alpha, NMS, Low, High : ) 根据颜色进行边缘提取

edges_image ( Image : ImaAmp, ImaDir : Filter, Alpha, NMS, Low, High : ) 边缘提取

skeleton ( Region : Skeleton : : ) 计算区域的框架 Skeleton == Region

frei_amp ( Image : ImageEdgeAmp : : ) Frei-chen 模板进行边缘检测(振幅)

frei_dir ( Image : ImageEdgeAmp, ImageEdgeDir : : ) Frei-chen 模板进行边缘检测(振幅和方向)

nonmax_suppression_dir ( ImgAmp, ImgDir : ImageResult : Mode : ) 使用方向图像 抑制所有的超过给定最大值的图像灰度值的点

gen_contours_skeleton_xld ( Skeleton : Contours : Length, Mode : ) 将系统框架转换成 XLD 轮廓

laplace ( Image : ImageLaplace : ResultType, MaskSize, FilterMask : ) 使用有限差分计算拉普拉斯变换

info_edges ( : : Filter, Mode, Alpha : Size, Coeffs ) 估计滤波器的宽度

kirsch_dir ( Image : ImageEdgeAmp, ImageEdgeDir : : ) 使用 Kirsch 算子计算出边缘(振幅和方向)

prewitt_amp ( Image : ImageEdgeAmp : : ) 使用 Prewitt 算子计算出边缘(振幅)

kirsch_amp ( Image : ImageEdgeAmp : : ) 使用 Kirsch 算子计算出边缘(振幅)

highpass_image ( Image : Highpass : Width, Height : ) 从高频成分提取的图像。

sobel_amp ( Image : EdgeAmplitude : FilterType, Size : ) 使用 Sobel 算子计算出边缘(振幅)

robinson_amp ( Image : ImageEdgeAmp : : ) 使用 Robinson 算子计算出边缘(振幅)

roberts ( Image : ImageRoberts : FilterType : ) 使用 Robert 算子计算边缘




部分内容摘自:小马_xiao

出处:http://www.cnblogs.com/xiaomaLV2/>

关于作者:专注halcon\opencv\机器视觉

本文版权归作者,未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接

其他边缘检测资源:

计算机视觉中的边缘检测



猜你喜欢

转载自blog.csdn.net/zzzkiti/article/details/80220120