一、在进行传统算法的形态学处理时,有时候开运算之后会把想要保留的区域剔除掉。此时可以用区域扩张算子重新把这些区域添加回来。这个可以用在OCR识别等应用。
二、算子
expand_gray (Regions, Image, ForbiddenArea, RegionExpand, ‘maximal’, ‘image’, 1)
expand_gray_ref (Regions, Image, ForbiddenArea, RegionExpand, ‘maximal’, ‘image’, Mean, 11)
这两个算子功能类似,下面分别介绍用法。
参数:
RegionClosing 是待扩张的区域
Image 是算子运行的原图
ForbiddenArea 是禁止扩张的区域
RegionExpand 是区域扩张后的新区域
‘maximal’ 算法迭代次数
‘image’ 区域扩张模式
1 是待扩张区域边缘灰度与等待扩张区域灰度差值的最小值
Mean 是待扩张区域边缘灰度的均值与被扩张区域灰度差值的最小值
这两个算子功能是相同,都是区域扩张。expand_gray是比较待扩张区域与被扩张区域边缘灰度的差值低于,最后一个参数Threshold。满足这个条件的区域都会被合并到扩张区域内。
expand_gray_ref 是给一个灰度参考值,这个值可以是待扩张区域的灰度均值,比较灰度参考值与被扩张区域边缘灰度的差值低于,最后一个参数Threshold 。满足这个条件的区域都会被合并到扩张区域内。
ForbiddenArea 这个参数可以利用gen_empty_region (EmptyRegion),设置为空区域EmptyRegion,此时只要满足条件,全图都可以扩张。如果ForbiddenArea参数不为空,则传进来的区域就是禁止扩张的区域。
三、案例
- Find a closed region of an image
read_image (Image, ‘claudia’)
gauss_filter (Image, Image, 5)
decompose3 (Image, Red, Green, Blue)
threshold (Red, RegionRed, 150, 255)
reduce_domain (Red, RegionRed, ImageRedSkin)
- Symmetry of gray values along a line (row)
symmetry (ImageRedSkin, ImageSymmetry, 80, 0, 0.5)
threshold (ImageSymmetry, Region, 190, 255) - Open a region with a rectangular structuring element
opening_rectangle1 (Region, RegionOpening, 1, 10)
rank_region (RegionOpening, RegionCount, 25, 25, 150)
closing_circle (RegionCount, RegionClosing, 53.5)
area_center (RegionClosing, Area, Row, Column)
gen_empty_region (EmptyRegion)
gen_rectangle1 (ROI_0, 281.219, 189.197, 403.094, 244.842)
expand_gray (RegionClosing, Red, EmptyRegion, RegionExpand, ‘maximal’, ‘image’, 1)
expand_gray (RegionClosing, Red, ROI_0, RegionExpand1, ‘maximal’, ‘image’, 1)
intensity (RegionClosing, Red, Mean, Deviation)
expand_gray_ref (RegionClosing, Red, EmptyRegion, RegionExpand2, ‘maximal’, ‘image’, Mean, 1)
smallest_rectangle1 (RegionClosing, Row1, Column1, Row2, Column2)
- Clip a region to a rectangle
clip_region (RegionExpand, RegionClipped, Row1, 0, Row2, 1000) - Close a region with a circular structuring element.
closing_circle (RegionClipped, RegionClosing1, 13.5) - Display calculated region
dev_display (Red)
dev_set_color (‘red’)
dev_set_draw (‘margin’)
dev_display (RegionClosing1)
原图
待扩张区域
禁止扩张区域为空,扩张后区域
禁止扩张区域为指定位置矩形,扩张后区域
expand_gray_ref算子,指定参考灰度为待扩张区域灰度均值。扩张后区域