您的位置:首页 > 其它

Edge Extraction -- 边缘提取

2016-02-16 15:33 288 查看


Edge Extraction -- 边缘提取

1. 一般过程



********************************************
* 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_close_window()

read_image(Image,'fuse')

get_image_size(Image,Width,Height)

dev_open_window(0,0,Width,Height,'black',WindowHandle)
*sobel 算子

sobel_amp(Image,EdgeAmplitude,'thin_sum_abs',3)
*二值

threshold(EdgeAmplitude,Region,30,255)
*骨骼化 -- 去掉多像素边缘

skeleton(Region,Skeleton)

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.

一个例子 Example: solution_guide/basics/edge_segments.hdev



********************************************
* edges_image(Image : ImaAmp, ImaDir : Filter,
* Alpha,
* 平滑用的
* NMS,
* nonmax_suppression_dir(...,NMS,...)
* Low, High :
) *hysteresis_threshold(...,Low,High,999,...)
*
* 低于Low的灰度值舍去
高于High的灰度值保留,中间的看情况
*
*********************************************

read_image(Image,'mreut')

get_image_size(Image,Width,Height)

dev_close_window()

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

edges_image (Image, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)

threshold (ImaDir, Regions,1, 255)

connection(Regions,ConnectionRegions)

count_obj(ConnectionRegions,Number)

gen_empty_obj(XLDContours)

dev_clear_window()

for i :=1 to Number by 1

select_obj(ConnectionRegions,SingleEdgeObject,i)

split_skeleton_lines(SingleEdgeObject,2,BeginRow,BeginCol,EndRow,EndCol)

for k :=0 to |BeginRow|-1 by 1

gen_contour_polygon_xld(Contour,[BeginRow[k],EndRow[k]],[BeginCol[k],\

EndCol[k]])

concat_obj(XLDContours,Contour,XLDContours)

endfor

endfor

dev_display(XLDContours)

一个例子 segmenting a color image



*******************************************
* edges_color(Image : ImaAmp, ImaDir : Filter, Alpha, NMS, Low, High :
)
* 根据颜色来提取边缘 与 edges_image 不同的地方 如图 b c 所示,足球场 红色和绿色分开了
*******************************************

dev_update_window('off')

dev_update_pc('off')

dev_update_var('off')

read_image(Image,'olympic_stadium')

get_image_size(Image,Width,Height)

dev_close_window()

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

edges_color (Image, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)

threshold(ImaAmp,RegionColor,1,255)

skeleton(RegionColor,EdgesColor)

dev_display(Image)

dev_display(EdgesColor)

stop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: