Halcon例程学习笔记(1)——Atoms

这个例程的目的是使用算子来找出结构不规则的原则,其中涉及到一些算子:

crop_rectangle1:从图像中截取矩形图像
gauss_filter:高斯滤波
watersheds:图像分水岭算法
smallest_rectangle1:平行于坐标轴的最小外接矩形

20190320210225150.png

Part Ⅰ 初始化程序

dev_update_off () 
dev_close_window ()
dev_set_draw ('margin')
dev_set_line_width (2)

都是基本的语句,其中例程中有一句:dev_update_window ('off') 意为不自动更新窗口,如果需要显示则必须调用dev_display,但是若将其设置为’ on ’ ,无明显变化。但是设置为’ off '可以显著降低运算时间。


Part Ⅱ 图像预处理


首先是读入图像,然后经过观察其图像下方有不规则区域,于是为了减少计算量,我们使用 crop_rectangle1 算子来提取下半部分进行处理。

read_image (Image, 'atoms') *读取图像
get_image_size (Image, Width, Height) *获取图像大小
crop_rectangle1 (Image, Image, Height / 2, 0, Height - 1, Width - 1) *裁剪区域

crop_rectangle1(Image : ImagePart : Row1, Column1, Row2, Column2 : ) 上一步的操作为获取图像大小,这个算子的参数即Image为输入图像,ImagePart 为输出图像,Row1,Column1为起始的左上角行列坐标,Row2,Column2为起始的右下角行列坐标。


其中在自己实现的时候,我将crop_rectangle1输入为crop_part,于是变成了截取相应的图像中相应的区域,而不是截取图像生成新的图像。crop_rectangle1后产生的图像为416X356,而crop_part后为416X710。由于误输入,产生的图像下半部分为黑色,怀疑为dev_update_window ('off') 有问题,经过多次排错,才发现这样的低级问题。

get_image_size (Image, Width, Height) *获取图片的大小
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowID) *打开一个适合图片的窗口
set_display_font (WindowID, 14, 'mono', 'true', 'false') *设置字体
dev_set_draw ('margin') *描绘边缘
dev_set_line_width (2) *设置字宽
dev_display (Image) *显示图片
disp_message (WindowID, 'Original image', 'window', 12, 12, 'black', 'true') *显示信息
disp_continue_message (WindowID, 'black', 'true') *显示继续
stop ()

Part Ⅲ 图像分割

* ****
* Segment image
* ****
* -> Using watershed
gauss_filter (Image, ImageGauss, 5) *高斯滤波
watersheds (ImageGauss, Basins, Watersheds) *分水岭算法
dev_display (Image) *显示图片 
dev_set_colored (12) * 使用多种颜色输出
dev_display (Watersheds) *显示图片
disp_message (WindowID, 'Watersheds', 'window', 12, 12, 'black', 'true') *显示信息
disp_continue_message (WindowID, 'black', 'true') *显示信息
stop ()

在使用watersheds时最好预先使用平滑算子(例如 binomial_filter or gauss_filter算子进行平滑)以减少输出区域的数目。


image.png

Part Ⅳ 处理区域操作

smallest_rectangle1 (Basins, Row1, Column1, Row2, Column2) *水平方向求出最小外接矩形
select_shape (Basins, SelectedRegions1, 'column1', 'and', 2, Width - 1) 
select_shape (SelectedRegions1, SelectedRegions2, 'row1', 'and', 2, Height - 1)
select_shape (SelectedRegions2, SelectedRegions3, 'column2', 'and', 1, Width - 3)
select_shape (SelectedRegions3, Inner, 'row2', 'and', 1, Height - 3)  *以上选择形状操作为去除边缘部分(因为受图片边缘影响为不规则矩形)
* -> Select irregularly shaped atoms
select_shape (Inner, Irregular, ['moments_i1','moments_i1'], 'or', [0,9.5e8], [1.5e8,1e10])*选出不规则矩形的形状 (moments_i1 几何矩)
dev_display (Image)
dev_set_line_width (1)
dev_set_color ('white')
dev_display (Inner)
dev_set_line_width (3)
dev_set_color ('red')
dev_display (Irregular)
disp_message (WindowID, 'Defects', 'window', 12, 12, 'black', 'true')


以下转自:http://www.cnblogs.com/iluzhiyong/p/4857877.html

Region特征一览:

特征备注

areaArea of the object对象的面积

rowRow index of the center中心点的行坐标

columnColumn index of the center中心点的列坐标

widthWidth of the region区域的宽度

heightHeight of the region区域的高度

row1Row index of upper left corner左上角行坐标

column1Column index of upper left corner左上角列坐标

row2Row index of lower right corner右下角行坐标

column2Column index of lower right corner右下角列坐标

circularityCircularity圆度0~1

compactnessCompactness紧密度0~1

contlengthTotal length of contour轮廓线总长

convexityConvexity凸性

rectangularityRectangularity矩形度0~1

raMain radius of the equivalent ellipse等效椭圆长轴半径长度

rbSecondary radius of the equivalent ellipse等效椭圆短轴半径长度

phiOrientation of the equivalent ellipse等效椭圆方向

anisometryAnisometry椭圆参数,Ra/Rb长轴与短轴的比值

bulkinessBulkiness椭圆参数,蓬松度πRaRb/A

struct_factorStructur Factor椭圆参数,Anisometry*Bulkiness-1

outer_radiusRadius of smallest surrounding circle最小外接圆半径

inner_radiusRadius of largest inner circle最大内接圆半径

inner_widthWidth of the largest axis-parallel rectangle that fits into the region最大内接矩形宽度

inner_heightHeight of the largest axis-parallel rectangle that fits into the region最大内接矩形高度

dist_meanMean distance from the region border to the center区域边界到中心的平均距离

dist_deviationDeviation of the distance from the region border from the center区域边界到中心距离的偏差

roundnessRoundness圆度,与circularity计算方法不同

num_sidesNumber of polygon sides多边形边数

connect_numNumber of connection components连通数

holes_numNumber of holes区域内洞数

area_holesArea of the holes of the object所有洞的面积

max_diameterMaximum diameter of the region最大直径

orientationOrientation of the region区域方向

euler_numberEuler number欧拉数,即连通数和洞数的差

rect2_phiOrientation of the smallest surrounding rectangle最小外接矩形的方向

rect2_len1Half the length of the smallest surrounding rectangle最小外接矩形长度的一半??smallest_rectangle2

rect2_len2Half the width of the smallest surrounding rectangle最小外接矩形宽度的一半

moments_m11Geometric moments of the region几何矩

moments_m20Geometric moments of the region几何矩

moments_m02Geometric moments of the region几何矩

moments_iaGeometric moments of the region几何矩

moments_ibGeometric moments of the region几何矩

moments_m11_invarGeometric moments of the region几何矩

moments_m20_invarGeometric moments of the region几何矩

moments_m02_invarGeometric moments of the region几何矩

moments_phi1Geometric moments of the region几何矩

moments_phi2Geometric moments of the region几何矩

moments_m21Geometric moments of the region几何矩

moments_m12Geometric moments of the region几何矩

moments_m03Geometric moments of the region几何矩

moments_m30Geometric moments of the region几何矩

moments_m21_invarGeometric moments of the region几何矩

moments_m12_invarGeometric moments of the region几何矩

moments_m03_invarGeometric moments of the region几何矩

moments_m30_invarGeometric moments of the region几何矩

moments_i1Geometric moments of the region几何矩

moments_i2Geometric moments of the region几何矩

moments_i3Geometric moments of the region几何矩

moments_i4Geometric moments of the region几何矩

moments_psi1Geometric moments of the region几何矩

moments_psi2Geometric moments of the region几何矩

moments_psi3Geometric moments of the region几何矩

moments_psi4Geometric moments of the region几何矩


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

作者:Lucas-zhang 

来源:CSDN 

原文:https://blog.csdn.net/qq_29600745/article/details/88699754 

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


本文出自勇哥的网站《少有人走的路》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