Halcon区域等分切割算子

一、区域等分,在做图像分割时,例如分割OCR字符,有时候会遇到粘连的比较严重的字符区域,无法通过Blob分析分割开。此时就可以用区域分割算子,强制分割字符区域。
二、算子说明
2.1partition_dynamic(Region : Partitioned : Distance, Percent : )
2.2partition_rectangle(Region : Partitioned : Width, Height : )

partition_dynamic(Region : Partitioned : Distance, Percent : )
定义:在垂直范围较小的位置对区域进行水平分区。
使用说明:partition_dynamic将输入Region水平划分为具有大约Distance宽度的区域。输入区域在其垂直范围相对较小的位置被分割。
输入区域被分割的位置由以下方法确定:首先,确定初始分割位置,使它们均匀分布在输入区域的水平范围内,即,使得所有结果部分具有相同的宽度. 为此,结果部分的数量 n 是通过将输入区域的宽度除以Distance并将结果四舍五入到最接近的整数值来确定的。现在通过将输入区域的宽度除以 n 来计算初始分割位置之间的距离。请注意,这些初始分割位置之间的距离通常与Distance不同. 然后,在初始分割位置的邻域中确定最终分割位置,使得输入区域在该邻域内具有最小垂直范围的位置处分割。最终分割位置与初始分割位置的最大偏差为Distance×Percent×0.01。
结果区域在Partitioned中返回。请注意,只有当输入区域的宽度大于 距离的 1.5 倍时,才会对输入区域进行分区。
partition_rectangle(Region : Partitioned : Width, Height : )
定义:将区域划分为大小大致相等的矩形。
使用说明:partition_rectangle将输入区域划分为范围为Width×Height的矩形。矩形在Partitioned中返回。该区域总是被分割成大小大致相等的矩形。如果请求的矩形大小无法做到这一点,则调整宽度和高度,以使生成的矩形的大小大致相等。如果区域小于给定大小,则其输出保持不变。只有当区域的大小至少是参数给定的矩形大小的 1.5 倍时,才会进行分区。
三、案例

read_image (Bottle2, 'bottle2')
threshold (Bottle2, Region, 0, 90)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 10000)
partition_rectangle (SelectedRegions, Partitioned, 30, 100)
dev_display (Bottle2)
dev_set_colored (12)
dev_display (Partitioned)

原图
在这里插入图片描述
结果图
在这里插入图片描述

* This example program shows how to use dots_image to segment a dot print.
dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
read_image (Image, 'needle1')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* Since the needle1 image would be fairly easy to segment, we will make life a
* little harder by adding a background texture to the image.
read_image (ImageNoise, 'angio-part')
crop_part (ImageNoise, ImagePart, 0, 0, Width, Height)
mult_image (Image, ImagePart, ImageResult, 0.015, 0)
* Use dots_image to enhance the dot print.
dots_image (ImageResult, DotImage, 5, 'dark', 2)
threshold (DotImage, Region, 80, 255)
* The following code connects the individual dots into characters.
closing_rectangle1 (Region, RegionClosing1, 1, 5)
closing_rectangle1 (RegionClosing1, RegionClosing2, 5, 1)
gen_rectangle2 (Rectangle, 10, 10, rad(45), 3, 0)
closing (RegionClosing2, Rectangle, RegionClosing3)
gen_rectangle2 (Rectangle, 10, 10, rad(135), 3, 0)
closing (RegionClosing3, Rectangle, RegionClosing4)
connection (RegionClosing4, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','height'], 'and', [100,20], [700,40])
* Since the closings may have resulted in merged characters, we need to
* separate them again.
partition_dynamic (SelectedRegions, Partitioned, 25, 20)
* Finally, we compute the characters' original shapes.
intersection (Partitioned, Region, Characters)
dev_display (ImageResult)
dev_set_colored (6)
dev_display (Characters)

原图
在这里插入图片描述
结果图
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值