Halcon Blob分析(二值化图像分割)

Blob分析

Blob分析的目的在于对图像中的2D形状进行检测和分析,得到诸如目标位置、形状、方向。Blob分析流程如下:

采集图像
图像分割
形态学处理
连通性分析
形态学处理
特征提取

算子

threshold(Image : Region : MinGray, MaxGray : )
Segment an image using global threshold.
该函数是最简单、快速、使用频率最高的方法。适用于环境稳定,目标和背景存在明显的灰度差的场合。threshod的阈值一般通过灰度直方图工具来确定。

示例

read_image(Image, 'clip')
*产生灰度直方图
gray_histo (Image, Image, AbsoluteHisto, RelativeHisto)
*根据灰度直方图产生灰度直方图区域,便于可视化
gen_region_histo (Region, RelativeHisto , 255, 255, 1)
*计算灰度值阈值(元组)
histo_to_thresh (RelativeHisto, 2, MinThresh, MaxThresh)
*期望目标灰度值
TargetGray:=23

*根据期望目标灰度值自动选择阈值
*最小阈值初始化
MinGray:=255
*最大阈值初始化
MaxGray:=0
*最小阈值元组从右往左遍历,第一个小于或等于期望目标灰度值的元素作为目标的最小阈值
for Index := |MinThresh|-1 to 0 by -1
    if(MinThresh[Index]<=TargetGray)
        MinGray:=MinThresh[Index]
        break
    endif
endfor
*最大阈值元组从左往右遍历,第一个大于或等于期望目标灰度值的元素作为目标的最大阈值
for Index1 := 0 to |MaxThresh|-1 by 1
    if(MaxThresh[Index1]>=TargetGray)
        MaxGray:=MaxThresh[Index1]
        break
    endif
endfor
*阈值分割
threshold (Image, Region1, MinGray, MaxGray)

threshold
bin_threshold(Image : Region : : )
Segment an image using an automatically determined threshold.
Description
bin_threshold segments a single-channel gray value image using an automatically determined threshold. First, the relative histogram of the gray values is determined. Then, relevant minima are extracted from the histogram, which are used as parameters for a thresholding operation. In order to reduce the number of minima, the histogram is smoothed with a Gaussian, as in auto_threshold. The mask size is enlarged until there is only one minimum in the smoothed histogram. The selected region contains the pixels with gray values from 0 to the minimum or for real images from the smallest value to the respective minimum. This operator is, for example useful for the segmentation of dark characters on a light paper.

示例

read_image(Image, 'clip')
bin_threshold (Image, Region)

bin_threshold

dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : )
Segment an image using a local threshold.
使用之前一般先将图像进行滤波处理(mean_image, gauss_image等)

使用场合

对于一些图像来说,无法通过一个全局阈值进行分割,比如:没有通用的参考图像来确定应用校正,或者图像的背景是非均匀的。但是物体在局部范围内通常比背景亮一些或暗一些。

示例

read_image (Image, 'alpha1')
*均值滤波
mean_image (Image, ImageMean, 21, 21)
dyn_threshold (Image, ImageMean, RegionDynThresh, 15, 'dark')

read_image (Image1, 'alpha1')
*中值滤波
median_image (Image1, ImageMedian, 'circle', 10, 'mirrored')
dyn_threshold (Image1, ImageMedian, RegionDynThresh1, 15, 'dark')

在这里插入图片描述
在这里插入图片描述

var_threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark : )
Threshold an image by local mean and standard deviation analysis.
阈值通过平均灰度值和标准差来确定。
这个算子对不合适的参数设置不敏感,只使用单个算子就能实现,但相比dyn_threshold,执行时间更长。

auto_threshold(Image : Regions : Sigma : )
Segment an image using thresholds determined from its histogram.
fast_threshold(Image : Region : MinGray, MaxGray, MinSize : )
Fast thresholding of images using global thresholds.
watersheds(Image : Basins, Watersheds : : )
Extract watersheds and basins from an image.
watersheds_threshold(Image : Basins : Threshold : )
==Extract watershed basins from an image using a threshold.==d

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MechMaster

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

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

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

打赏作者

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

抵扣说明:

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

余额充值