Halcon 边缘提取之计算给定前景区域的连接背景分量 background_seg.hdev

引言

边缘提取,计算给定前景区域的连接背景分量


一、结果

1.1 读取图像

在这里插入图片描述

1.2 处理后结果

在这里插入图片描述


二、Halcon代码

* Determine the connected components of the background of given regions
* 
read_image (Image, 'fabrik')
* Detect edges
//sobel_amp — 使用 Sobel 算子检测边缘(幅度)
sobel_amp (Image, EdgeAmplitude, 'thin_sum_abs', 3)
//threshold — 使用全局阈值分割图像
threshold (EdgeAmplitude, Edges, 5, 255)
background_seg (Edges, BackgroundRegions)
* Fill up holes in regions based on shape feature 'area'
fill_up_shape (BackgroundRegions, RegionFillUp, 'area', 1, 40)
dev_clear_window ()
dev_set_colored (6)
dev_display (RegionFillUp)

三、主要算子分析

1.sobel_amp (Operator)

sobel_amp — 使用 Sobel 算子检测边缘(幅度)。

sobel_amp (Image, EdgeAmplitude, 'thin_sum_abs', 3)

在这里插入图片描述

函数解析

sobel_amp(Image : EdgeAmplitude : FilterType, Size : )
//参数
	Image (input_object)            //input image.
	EdgeAmplitude (output_object)   //边缘幅度(梯度幅度)图像。
	FilterType (input_control)      //Filter type.
		Default value: 'sum_abs'
		List of values: 'sum_abs', 'sum_abs_binomial', 'sum_sqrt', 
		'sum_sqrt_binomial', 'thin_max_abs', 'thin_max_abs_binomial', 
		'thin_sum_abs', 'thin_sum_abs_binomial', 'x', 'x_binomial', 
		'y', 'y_binomial'
		List of values (for compute devices): 'sum_abs', 'sum_sqrt', 
		'x', 'y', 'sum_abs_binomial', 'sum_sqrt_binomial', 
		'x_binomial', 'y_binomial'
	Size (input_control)         //Size of filter mask.
		Default value: 3
		List of values: 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 
		31, 33, 35, 37, 39

sobel_amp 计算图像的一阶导数并用作边缘检测器。 该过滤器基于以下过滤器掩码:

在这里插入图片描述
根据所选的过滤器类型,这些掩码的使用方式不同。 (在下文中,a 和 b 表示针对一个特定像素将图像与 A 和 B 进行卷积的结果。)

在这里插入图片描述
这里,对于垂直最大值(掩码 A)和水平最大值(掩码 B),thin(x) 分别等于 x,否则为 0。因此,对于“thin_sum_abs”和“thin_max_abs”,梯度图像被细化。对于过滤器类型“x”和“y”,如果输入图像的类型为字节,则输出图像的类型为 int1,否则为 int2 类型。对于大小为 3x3 的 Sobel 算子,直接应用相应的滤波器 A 和 B,而对于较大的滤波器大小,输入图像首先使用大小为 2 的高斯滤波器(参见 gauss_image)或二项式滤波器(参见binomial_filter)进行平滑.上述FilterType的值选择了高斯滤波器。此处,必须使用 Size = 5、7、9、11 或 13。通过将“_binomial”附加到上述 FilterType 值来选择二项式过滤器。这里,Size 可以在 5 到 39 之间选择。此外,可以通过在 Size 中传递两个值来选择不同的列和行方向平滑量。这里,Size的第一个值对应的是掩码宽度(列方向平滑),第二个值对应二项式滤波器的掩码高度(行方向平滑)。二项式过滤器只能用于 byte、uint2 和 real 类型的图像。由于平滑减少了边缘幅度,在这种情况下,边缘幅度乘以因子 2 以防止信息丢失。所以,

在这里插入图片描述
对于 sobel_amp,使用 SIMD 技术实现了特殊优化 FilterType = ‘sum_abs’。 这些特殊优化的实际应用由系统参数“mmx_enable”控制(参见 set_system)。 如果’mmx_enable’ 设置为’true’(并且SIMD 指令集可用),则使用SIMD 技术执行内部计算。 请注意,SIMD 技术在大而紧凑的输入区域上表现最佳。 根据输入区域和硬件的能力,使用 SIMD 技术执行 sobel_amp 甚至可能比不使用 SIMD 技术花费更多的时间。

sobel_amp 可以在 OpenCL 设备上针对过滤器类型“sum_abs”、“sum_sqrt”、“x”和“y”(以及它们的二项式变体)执行。 请注意,当对 Size > 3 使用高斯过滤时,结果可能会因 CPU 实现而异。

2.threshold (Operator)

threshold — Segment an image using global threshold.

...
threshold (EdgeAmplitude, Edges, 5, 255)
...

在这里插入图片描述

函数解析

threshold(Image : Region : MinGray, MaxGray : )
	//参数
	Image (input_object)           //input image
	Region (output_object)         //Segmented region.
	MinGray (input_control)        //Lower threshold for the gray values.
		Default value: 128.0
		Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0
	MaxGray (input_control)       //Upper threshold for the gray values.
		Default value: 255.0
		Suggested values: 0.0, 10.0, 30.0, 64.0, 128.0, 200.0, 220.0, 255.0
		Restriction: MaxGray >= MinGray
		

3.background_seg (Operator)

background_seg — 确定给定区域背景的连通分量。

...
background_seg (Edges, BackgroundRegions)
...

在这里插入图片描述

函数解析

background_seg(Foreground : BackgroundRegions : : )
	//参数
	Foreground (input_object)            //Input regions.
	BackgroundRegions (output_object)    //Connected components of the background.
	

background_seg 确定前景中给定的前景区域的背景的连通分量。 该算子通常在边缘算子之后使用以确定被提取的边缘包围的区域。 使用 4-邻域确定连接的组件。

4.fill_up_shape (Operator)

fill_up_shape — 填充具有给定形状特征的区域中的孔。

// Fill up holes in regions based on shape feature 'area'
fill_up_shape (BackgroundRegions, RegionFillUp, 'area', 1, 40)
...

在这里插入图片描述

函数解析

fill_up_shape(Region : RegionFillUp : Feature, Min, Max : )
	Region (input_object)          //Input region(s).
	RegionFillUp (output_object)   //Output region(s) with filled holes.
	Feature (input_control)        //Shape feature used.
		Default value: 'area'
		List of values: 'anisometry', 'area', 'compactness', 'convexity', 
		'inner_circle', 'outer_circle', 'phi', 'ra', 'rb'
	Min (input_control)    //Minimum value for Feature.
		Default value: 1.0
		Suggested values: 0.0, 1.0, 10.0, 50.0, 100.0, 500.0, 1000.0, 10000.0
		Typical range of values: 0.0 ≤ Min
	Max (input_control)    //Maximum value for Feature.
		Default value: 100.0
		Suggested values: 10.0, 50.0, 100.0, 500.0, 1000.0, 10000.0, 100000.0
		Typical range of values: 0.0 ≤ Max
		

fill_up_shape 填充具有给定形状特征的输入区域区域中的那些空洞。 参数 Feature 确定要使用的形状特征,而 Min 和 Max 确定形状特征必须位于的范围内,以便填充孔。

四、与MFC相结合

在这里插入图片描述
详细过程参见MFC与HALCON混合编程三之滑动条控件_选择阈值—backgroundSeg

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值