Blob分析及形态学分析
目录
Blob分析的基本思想:
Blob分析主要流程:
Blob分析
分割: Binary Threshold
分割: Histogram
分割: 动态阈值
全局阈值与动态局部阈值的比较
形态学处理
连通区域 connetion
形态学算子
特征提取
提取特征 常用相关算子
区域特征: rectangularity
Blob分析的基本思想:
图像中相关联物体(前景)的像素可以通过其灰度值来标
识
Blob分析主要流程:
获取图像、分割图像、提取特征

一个简单的例子(非常理想的情况)
read_image (Image, ’particle’)
threshold (Image, BrightPixels, 120, 255)
connection (BrightPixels, Particles)
area_center (Particles, Area, Row, Column)
Blob分析
threshold 定义
threshold 算子 速度最快使用频率最高的分 割算法 如果目标体与背景之间存在灰度差,则 threshold 首先被 使用 如果环境稳定,阈值可在离线状态下一次确定
分割: Binary Threshold
自动地全局阈值的方法
多次平滑直方图
寻找峰值
峰谷作为阈值
bin_threshold (Image, Region)
分割: Histogram
自动地全局阈值的方法
统计直方图
寻找出现频率最高的灰度值
把比最高灰度值小一定灰阶值的灰度值作为阈值
gray_histo (Image, Image, AbsoluteHisto,
RelativeHisto)
PeakGray := sort_index(AbsoluteHisto)[255]
threshold (Image, Region, 0, PeakGray-25)
分割: 动态阈值
动态阈值分割
•
很多情况下由于背景不均一,无
法确定全局阈值
•
目标体经常表现为比背景局部亮
一些或暗一些
•
需要通过其邻域找到一个合适的
阈值进行分割
•
如何确定其邻域?
可以通过一些平滑滤波算子来确
定邻域,例如 mean_image
binomial_filter 等
动态阈值分割,其中S为平滑后的输入图像
x y R g x y s x y t

全局阈值与动态局部阈值的比较
动态局部阈值
– 通过均值滤波确定邻域
– 滤波器mask尺寸大于字符笔画的宽度
– 选择所有比其邻域暗的像素
mean_image (Image, ImageMean, 21, 21)
dyn_threshold (Image, ImageMean,
Region, 15, 'dark')

watersheds_threshold 函数
方法
使用传统的 watersheds 算法
通过阈值合并盆地 :
W
B 1
B 2
max( W B 1 , W B 2 ) Threshold

形态学处理
• 分割之后,往往需要对区域做进一步处理才能满足要求
• 常用形态学相关算子
connection, select_shape, opening_circle, closing_circle,
opening_rectangle1, closing_rectangle1, difference,
intersection, union1, shaps_trans, fill_up
• 高级算子
boundary, skeleton 等
连通区域 connetion
阈值分割后,需要提取目标物体,为了提取目标物体不得不先找到连通区域
提取连通域的关键是领域搜索的类型
在 所有的案例中 8 领域法是默认的

形态学算子
任意的结构元素
任意尺寸的结构元素
非常有效的处理
巨大的算子集合 : 44 个算子
经典算子
Erosion, dilation, opening, closing
高级算子
top-hat, bottom-hat, hit-or-miss, boundary
特殊算子
Fitting, pruning, thickening, thinning, skeleton

定义
Operator
union1 : Union of all regions in one variable
union2 : Unify all regions in the second parameter with each region in the first
parameter
Usage
Generate regions by combining primitive shapes
Combine segmentation results

Definition
Operator
intersection : Intersect each region of the first parameter with the union of
all regions of the second parameter
Usage
Generate regions by combining primitive shape
Use as a result those points where two methods return pixels

Operator
difference : Subtract from all regions of the first parameter the union of all
regions of the second parameter
Usage
Generate regions by combining primitive shape
Use as a result those points where one method but not the other one returns
pixels

Operator
complement : Calculate the complement of each input region
Usage
Use as a result those pixels which are not part of the segmentation
Note: with set_system the behavior can be controlled
'clip_region' on: the difference with the maximum image size is calculated
'clip_region' off: only the smart complement is applied

特征提取
特征描述了区域的特有属性
区域特征 ( 形状特征 ) 描述了区域的几何特征,这些特征不依赖
于灰度值
用途:
分割后,通过特征提取选择出所需的目标物体
区域分类 , 比如 OCR
测量
质量检测
提取特征 常用相关算子
area_center, smallest_rectangle1, smallest_rectangle2,
compactness, eccentricity, elliptic_axis, area_center_gray,
intensity, min_max_gray
Region Feature: Moments

区域特征 : 更多特征
smallest_circle :
Convexity( 凸状性 ) : 区域面积和凸形外轮廓的比例
Contlength( 长度 ) : 区域边界长度
Compactness( 紧密度 ) :




区域特征: rectangularity
除了圆形和椭圆形外,长方形是一种典型的形状
典型的形状特征比如比如 roundness, circularity, 或者 compactness 不适用于
选择长方形
输入区域
等价长方形
difference

select_shape( Regions : SelectedRegions : Features , Operation , Min , Max : )
read_image(Image,'monkey')
threshold(Image,S1,160,255) connection(S1,S2)
select_shape(S2,Eyes,['area','anisometry'],'and',[500,1.0],[50000,1.7])
disp_region(Eyes,WindowHandle)