Edge Extraction -- 邊緣提取

http://www.cnblogs.com/xiaomaLV2/archive/2011/12/28/2304814.html

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 : ImaAmpImaDir : Filter,
*                             Alpha,           * 平滑用的
*                           NMS,               * nonmax_suppression_dir(...,NMS,...)
*                        LowHigh : )       *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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值