Halcon 金属疤痕检测(图像增强、区域排序、灰度扩张)

链接:https://pan.baidu.com/s/15zKJ3Ea_EZJRbYE72V5pgw
提取码:pzg0 请添加图片描述

* 1.读取并显示图片 *************************************
dev_close_window ()
read_image (Image, './img.png')
get_image_size (Image, Width, Height)
dev_open_window_fit_size (0, 0, Width, Height, -1, -1, WindowHandle)
dev_display (Image)

set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw ('margin')

dev_set_line_width (3)

rgb1_to_gray (Image, GrayImage)

* 图像增强 
emphasize (GrayImage, ImageEmphasize, Width, Height, 5) 
mult_image (ImageEmphasize, ImageEmphasize, ImageResult, 1, 0)

* 2.获取处理区域 *************************************
* 二值化分析
threshold (ImageResult, Region, 200, 255)
* 形态学 膨胀
dilation_rectangle1 (Region, RegionDilation, 3, 3)

* 连通域分析与筛选
connection (RegionDilation, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 999999999)
* 形态学 膨胀
dilation_rectangle1 (SelectedRegions, RegionDilation1, 2, 2)
* 孔洞填充
fill_up (RegionDilation1, RegionFillUp)

* 获取全图区域
get_domain (GrayImage, Domain)
* 获取三条黑色 边缘区域
difference (Domain, RegionFillUp, RegionDifference)
* 连通域分析
connection (RegionDifference, ConnectedRegions1)
* 形状变换 带角度矩形
shape_trans (ConnectedRegions1, RegionTrans, 'rectangle2')
* 去除边缘区域
difference (Domain, RegionTrans, RegionDifference1)
* 连通域分析
connection (RegionDifference1, ConnectedRegions2)
* 连通域排序(水平排序)
sort_region (ConnectedRegions2, SortedRegions, 'first_point', 'true', 'column')
* 获取第2个区域与第三个区域(处理区域)
select_obj (SortedRegions, ObjectSelected2, 2)
select_obj (SortedRegions, ObjectSelected3, 3)

* 合并排序为 23的区域
union2 (ObjectSelected2, ObjectSelected3, RegionUnion)
stop()

* 3.检测缺陷 *************************************
* 聚焦处理区域
reduce_domain (ImageResult, RegionUnion, ImageReduced)
* 二值化处理
threshold (ImageReduced, Region1, 0, 20)
* 开运算 
opening_rectangle1 (Region1, RegionOpening, 3, 3)
* 连通域分析
connection (RegionOpening, ConnectedRegions3)

* 生成空的区域
gen_empty_region (EmptyRegion)
* 灰度扩张 (图像上填充周边相近区域)
expand_gray (ConnectedRegions3, ImageResult, EmptyRegion, RegionExpand, \
             'maximal', 'image', 16)
* 处理区域 与 结果区域 交集
intersection (RegionUnion, RegionExpand, RegionIntersection)
* 闭运算
closing_circle (RegionIntersection, RegionClosing, 3.5)
* 连通域分析与筛选
connection (RegionClosing, ConnectedRegions4)
select_shape (ConnectedRegions4, SelectedRegions1, 'area', 'and', 250, 99999)

* 生成连通域区域XLD
gen_contour_region_xld (SelectedRegions1, Contours, 'border')
* 平滑显示
smooth_contours_xld (Contours, SmoothedContours, 5)

* 结果显示
dev_display (Image)
dev_set_color ('yellow')
dev_display (SmoothedContours)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

廷益--飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值