Halcon学习(4-2)Region处理:选择区域,分割图像

一,基本的图像通道知识


在图像处理中有一个很重要的概念叫图像通道,在RGB色彩模式下就是指那单独的红色、绿色、蓝色部分。也就是说,一幅完整的图像,是由红色绿色蓝色三个通道组成的。他们共同作用产生了完整的图像。

    一幅完整的图像,红色绿色蓝色三个通道缺一不可。即使图像中看起来没有蓝色,只能说蓝色光的亮度均为0,但不能说没有蓝色通道存在

    “存在、亮度为零”和“不存在”是两个不同的概念。

    一幅图像,如果关闭了红色通道,那么图像就偏青色。如果关闭了绿色通道,那么图像就偏洋红色。如果关闭了蓝色通道,那么图像就偏黄色。

这个现象再次印证了反转色模型:红色对青色、绿色对洋红色、蓝色对黄色。


    如果察看单个通道,发现每个通道都显示为一幅灰度图像(不能说是黑白图像)。某个通道的灰度图像中的明暗对应该通道色的明暗,从而表达出该色    光在整体图像上的分布情况。由于通道共有3个,所以也就有了3幅灰度图像。

    通道中的纯白,代表了该色光在此处为最高亮度,亮度级别是255

 通道中的纯黑,代表了该色光在此处完全不发光,亮度级别是0

 介于纯黑纯白之间的灰度,代表了不同的发光程度,亮度级别介于1至254之间。

 灰度中越偏白的部分,表示色光亮度值越高,越偏黑的部分则表示亮度值越低。

 现在可以明白为何通道用灰度表示了吧?因为通道中色光亮度从最低到最高的特性,正符合灰度模式那种从黑到白过渡的表示。正是因为灰度的这种特性,使得它在以后还被应用到其它地方。通道中的灰度,与颜色调板的灰度滑块是对应的。


二,单通道图像分割 
1阈值分割 
全局阈值,局部阈值法,直方图自动阈值(自适应阈值)

指定全局阈值 

threshold( Image: Region: MinGray, MaxGray)  //人工设置阈值

局部阈值法,后面再加以描述

直方图自动阈值(自适应阈值) 

auto_threshold( Image: Region:Sigma:)

//自动阈值输入必须是是单通道图像,会有多阈值分割,Sigma用于对灰度直方图进行高斯平滑,决定了平滑的程度(分割细致程度),当sigma很大时,灰度直方图基本会被平滑为只剩下一个波峰,而分割根据平滑后直方图的波谷来进行的,Sigma小,分割的越细致。

image.png

三,彩色图像的分割 

decompose3
trans_from_rgb(red,green,blue,result1,result2,result3,colortypespace)

二 相关的算子详解


选择区域(分割图像)


原图如下,需要选择其中的3个焊点。

image.png

代码:

    threshold (ImageReduced, Regions1, 0, 201)
    connection(Regions1, ConnectedRegions)
    count_obj(ConnectedRegions, N1)

    select_obj(ConnectedRegions, ObjectSelected, 3)
    select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
    count_obj(SelectedRegions, N2)


代码解释:


threshold阈值算子


threshold (ImageReduced, Regions1, 0, 201)
这个是取阈值的算子,阈值是分割图像的一种常见办法。它选择满足输入控制参数的灰度值之内的灰度值,当所有的像素点都满足这个区域的话,就形成一个区域。如下图所示是选择灰度值在0和201之间的像素构成一个区域。


可以如下图这样调出向导(灰度直方图),很方便的插入代码。

image.png


connection(Regions1, ConnectedRegions)
count_obj(ConnectedRegions, N1)

取连接区域,然后计数,这个例子中连通区域数量N1=4



select_obj(ConnectedRegions, ObjectSelected, 3)
这句可以选中4个连通区域中的一个,索引号为3的区域。

image.png


select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
count_obj(SelectedRegions, N2)

通过按area大小范围来过滤shape。这里选中了3个区域,N2=3

image.png


select_shape算子, 跟据特征值选择区域。


其相关功能的算子可以求Region指定特征值:region_features(Regions : : Features : Value)

select_shape算子可以由向导(特征直方图)来进行可视化操作,可以很方便的生成代码。如下图所示:

image.png

如上图所示的“特征”种类及其意义见下表:


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椭圆参数,蓬松度π*Ra*Rb/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几何矩


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

作者:hackpig
来源:www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!


halocn基础系列教程列表:


Halcon学习(27-2)halcon测量技术:找线

Halcon学习(27-1)halcon测量技术:亚像素,亚像素精度

Halcon学习(26)dev_get_preferences的用法

Halcon学习(25)if、switch和try

Halcon学习(24)总结(1)

Halcon学习 (22-2) 标定助手

Halcon学习(22)摄像机标定(函数详解)

Halcon学习(21)摄像机标定常用函数(2)

Halcon学习(20)摄像机标定常用函数(1)

Halcon学习(19)标定文件的生成

Halcon学习(18)如何制作标定板

Halcon学习(17)标定板的规格

Halcon学习(16)函数调用

Halcon学习(15)角点检测

Halcon学习(14)绘图

Halcon学习(13)参数和数据结构

Halcon学习(11)边缘检测

Halcon学习(9)两幅图像之间处理

Halcon学习(8)文本操作

Halcon学习(7)图像中显示文字

Halcon学习(6)计数与排序

Halcon学习(5)获取特征点

Halcon学习(4-7)Region相关的算子

Halcon学习(4-6)Region处理:动态阈值,分水岭

Halcon学习(4-5)Region处理:合并区域,扩大和缩小区域,取区域特征值

Halcon学习(4-4)Region处理: 区域相减,区域求补集

Halcon学习(4-3)Region处理:区域连通

Halcon学习(4-2)Region处理:选择区域,分割图像

Halcon学习(4-1)ROI感兴趣区域,reduce_domain和crop_domain,鼠标绘制区域

Halcon学习(3)赋值与数组操作

Halcon学习(2)图像获取与相关参数

Halcon学习(1)读取多张图片


视觉检测之产品瑕疵检测


视觉检测之产品瑕疵检测(1)污点检测

视觉检测之产品瑕疵检测(2)金属表面疤痕

视觉检测之产品瑕疵检测(3)赃污检测

视觉检测之产品瑕疵检测(4)表面划痕


视觉检测之焊点检测


视觉检测之焊点检测(五):动态定位焊点区域ROI续

视觉检测之焊点检测(六):过滤非焊点区域的方法总结

 视觉检测之焊点检测(四):动态定位焊点区域ROI

视觉检测之焊点检测(三):从干扰背景中提取焊点

视觉检测之焊点检测(二):基于形态学的基础焊点检测方法

视觉检测之焊点检测(一):客户需求和焊点检测工艺要求


模板匹配/仿射变换


halcon之屌炸天的变形匹配(1)

Halcon二维仿射变换实例探究

Halcon中模板匹配方法的总结归纳

Halcon之NCC模板扫盲贴

HALCON形状模板匹配shape_model经验及例子

halcon模板匹配,创建模板的总结

Halcon视觉检测——基于灰度的模板匹配

halcon模板匹配 scaled_shape_model模板的另一个例子

Halcon二维仿射变换实例探究

Halcon中两种实现旋转的方法rotate_image和affine_trans_image

halcon的 shape_model模板匹配的算子使用流程的总结

find_shape_mode参数详解及时长优化

halcon的三种模板匹配方法总结

Halcon基于形状特征的模板匹配



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