十九.Blob Analysis之三(一些例子)

算子:

1.union1(Region : RegionUnion : : )

计算所有输入区域的并集,并返回计算结果。

2.skeleton(Region : Skeleton : : )

求区域的骨架,即包含在区域内的滚动最大圆圆心轨迹。

3.intensity(Regions, Image : : : Mean, Deviation)

计算区域灰度值的均值和方差。

例1.检测金属表面划痕

* surface_scratch.hdev: extraction of surface scratches via local thresholding and morphological post-processing
*
dev_close_window ()
dev_update_window ('off')
* ****
* step: acquire image
* ****
read_image (Image, 'surface_scratch')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Width, WindowID)
set_display_font (WindowID, 12, 'Courier', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (4)
dev_display (Image)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: segment image
* ****
* -> using a local threshold
mean_image (Image, ImageMean, 7, 7)
dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark')//阈值小于均值滤波像素灰度-5的像素被提取//
* -> extract connected components
connection (DarkPixels, ConnectedRegions)
dev_set_colored (12)
dev_display (ConnectedRegions)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: process regions
* ****
* -> select large regions
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000)//提取面积在10到1000之间的区域//
dev_display (Image)
dev_display (SelectedRegions)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* -> visualize fractioned scratch
open_zoom_window (0, round(Width/2), 2, 303, 137, 496, 3, WindowHandleZoom)

//放大并显示感兴趣区域,内部函数//
dev_set_color ('blue')
dev_display (Image)
dev_display (SelectedRegions)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* -> merge fractioned scratches via morphology
union1 (SelectedRegions, RegionUnion)  //对区域进行并集运算//
dilation_circle (RegionUnion, RegionDilation, 3.5)//对区域进行膨胀运算//
dev_display (Image)
dev_display (RegionDilation)
disp_continue_message (WindowID, 'black', 'true')
stop ()
skeleton (RegionDilation, Skeleton)//求并区域的骨架//

connection (Skeleton, Errors)//连通骨架//
dev_set_colored (12)
dev_display (Image)
dev_display (Errors)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* -> distinguish small and large scratches
close_zoom_window (WindowHandleZoom, Width, Height)
select_shape (Errors, Scratches, 'area', 'and', 50, 10000)//选出抓痕直线//
select_shape (Errors, Dots, 'area', 'and', 1, 50)//选出抓痕点//
dev_display (Image)
dev_set_color ('red')
dev_display (Scratches)
dev_set_color ('blue')
dev_display (Dots)

结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值