(halcon实例)最大稳定极值区域(MSER)方法进行图像分割



image.png

* This example demonstrates the functionality of segment_image_mser.
* 
* Create artificial example image.
create_example_image (Image)
* 
dev_update_off ()
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
Message := 'The operator \'segment_image_mser\' extracts'
Message[1] := 'maximally stable extremal regions (MSER) in the image.'
Message[2] := 'MSERs are regions that do not change their size'
Message[3] := 'significantly over multiple consecutive thresholds.'
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with default parameters and Polarity set to 'dark'.
segment_image_mser (Image, MSERDark, MSERLight, 'dark', 10, [], 15, [], [])
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'With \'Polarity\' set to \'dark\', the operator extracts'
Message[1] := 'regions which are darker than their background.'
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with default parameters and Polarity set to 'light'.
segment_image_mser (Image, MSERDark, MSERLight, 'light', 10, [], 15, [], [])
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'With \'Polarity\' set to \'light\', the operator extracts'
Message[1] := 'regions which are brighter than their background.'
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with MinArea and MaxArea set to exclude too
* small and too large regions.
MinArea := 2000
MaxArea := 15000
segment_image_mser (Image, MSERDark, MSERLight, 'both', MinArea, MaxArea, 15, [], [])
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'The parameters \'MinArea\' and \'MaxArea\' can be used to'
Message[1] := 'restrict the size of the returned regions.'
Message[2] := 'Increasing \'MinArea\' can reduce the computation time.'
Message[3] := 'Here: MinArea = ' + MinArea + ', MaxArea = ' + MaxArea
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with further setting Delta to a lower value.
* This reduces the number of regions.
Delta := 5
segment_image_mser (Image, MSERDark, MSERLight, 'both', 100, [], Delta, [], [])
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'Furthermore, \'Delta\' can be used to regulate'
Message[1] := 'the number of thresholds over which a region needs'
Message[2] := 'to be stable. Decreasing the value of Delta'
Message[3] := 'results in more regions.'
Message[4] := 'Here: Delta = ' + Delta
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with further setting the generic parameter
* 'max_variation' to a larger value. This increases the number of regions.
MaxVariation := 1.0
segment_image_mser (Image, MSERDark, MSERLight, 'both', 100, [], Delta, 'max_variation', MaxVariation)
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'The generic parameter \'max_variation\' can be used to'
Message[1] := 'regulate how much a region is allowed to vary'
Message[2] := 'between the range of thresholds. A larger value'
Message[3] := 'increases the number of regions.'
Message[4] := 'Here: \'max_variation\' = ' + MaxVariation
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* Call segment_image_mser with further setting the generic parameter
* 'min_diversity' to a larger value. This increases the number of overlapping regions.
MinDiversity := 5.5
segment_image_mser (Image, MSERDark, MSERLight, 'both', 100, [], Delta, ['max_variation','min_diversity'], [MaxVariation,MinDiversity])
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'The generic parameter \'min_diversity\' can be used to'
Message[1] := 'regulate the number of multiple (overlapping)'
Message[2] := 'responses. A larger value reduces the number'
Message[3] := 'of overlapping regions. '
Message[4] := 'Here: \'min_diversity\' = ' + MinDiversity
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
stop ()
* 
* It is possible to set the minimal and maximal considered gray value with
* the generic parameter 'min_gray' and 'max_gray'
MinGray := 50
MaxGray := 210
count_seconds (S1)
segment_image_mser (Image, MSERDark, MSERLight, 'both', 100, [], Delta, ['min_gray','max_gray'], [MinGray,MaxGray])
count_seconds (S2)
TimeMinMaxGray := (S2 - S1) * 1000
* Run again with defaults to compare execution times
count_seconds (S1)
segment_image_mser (Image, MSERDark, MSERLight, 'both', 100, [], Delta, [], [])
count_seconds (S2)
Time := (S2 - S1) * 1000
disp_dark_light_results (Image, MSERDark, MSERLight, WindowHandle)
Message := 'The generic parameter \'min_gray\' and \'max_gray\' set the'
Message[1] := 'minimal and maximal considered gray value.'
Message[2] := 'This may reduce the runtime considerably.'
Message[3] := 'Here: \'min_gray\' = ' + MinGray + ', \'max_gray\' = ' + MaxGray
Message[4] := 'Runtime (with/without gray range set): ' + TimeMinMaxGray$'.1f' + '/' + Time$'.1f' + ' ms'
dev_disp_text (Message, 'window', 12, 12, 'black', [], [])


--------------------- 

作者:hackpig

来源:www.skcircle.com

版权声明:本文为博主原创文章,转载请附上博文链接!


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864