# Region在connection前后进行“交并差”等操作的异同

connection直译为“连接”。其实它的功能不是连接，它的功能是确定区域之间的连接关系，如果简单粗暴地解释的话，可以认为：connection的意思是“打散”，将不连接的区域打散成一个一个的区域。

1、用connection之后的region集合减去单一region

 1 read_image (Right, '未标题-1.jpg')
2 threshold (Right, One_Circle, 0, 80)
3 opening_circle (One_Circle, One_Circle, 3.5)
4
5 threshold (Right, Four_Reg, 100, 200)
6 opening_circle (Four_Reg, Four_Reg, 3.5)
7
8 dilation_circle (One_Circle, One_CircleDilation, 29.5)
9
10 *ConnectedRegions有几个值，xxx里就有几个值，这里是4个
11 connection (Four_Reg, ConnectedRegions)
12 difference (ConnectedRegions, One_CircleDilation, xxx)
13 area_center (xxx, Area, Row, Column)
14
15 *这里yyy只有3个值
16 difference (Four_Reg, One_CircleDilation, RegionDifference1)
17 connection (RegionDifference1, yyy)
18 area_center (yyy, Area1, Row1, Column1)

Area := [1307, 4448, 4534, 0]

Area1 := [1307, 4448, 4534]

2、用connection之后的region集合减去多个region

3、用单个region减去其他region在connection之后的region集合

 1 read_image (Right, '未标题-1.jpg')
2 threshold (Right, One_Circle, 0, 80)
3 opening_circle (One_Circle, One_Circle, 3.5)
4
5 threshold (Right, Four_Reg, 100, 200)
6 opening_circle (Four_Reg, Four_Reg, 3.5)
7 gen_rectangle1 (ROI_0, 0, 190.5, 288, 242.5)
8 union2 (ROI_0, Four_Reg, RegionUnion)
9
10 connection (RegionUnion, RegionUnion)
11
12 dilation_circle (One_Circle, One_Circle_Dilation, 29.5)
13
14 difference (One_Circle_Dilation, RegionUnion, Region_Result)
15
16 connection (Region_Result, Region_Result_Connected)

difference(Region, Sub : RegionDifference : : )

1、如上，对于difference算子来说，它的效果形状约等效于签名中的Region区域union1之后减去Sub区域union1之后的结果。简记为：union1(Region) - union1(Sub).   （注意，仅仅是效果形状）

2、签名中，差集结果RegionDifference 中元素的个数和Region一致，其中可能有些region的面积为0，或者有单个region被分隔开没有连在一起。

 1 read_image (Right, '未标题-1.jpg')
2 threshold (Right, One_Circle, 0, 80)
3 opening_circle (One_Circle, One_Circle, 3.5)
4
5 threshold (Right, Four_Reg, 100, 200)
6 opening_circle (Four_Reg, Four_Reg, 3.5)
7 gen_rectangle1 (ROI_0, 0, 190.5, 288, 242.5)
8 union2 (ROI_0, Four_Reg, RegionUnion)
9
10 connection (RegionUnion, RegionUnion)
11
12 dilation_circle (One_Circle, One_Circle_Dilation, 29.5)
13
14
15 intersection (One_Circle_Dilation, RegionUnion, RegionIntersection)
16
17 intersection (RegionUnion, One_Circle_Dilation, RegionIntersection1)
18
19 area_center (RegionIntersection1, Area, Row, Column)
20 union1 (RegionIntersection1, RegionUnion1)
21 connection (RegionUnion1, ConnectedRegions)

RegionIntersection 和 RegionIntersection1的形状都是一样的，注意仅是形状。

union2(Region1, Region2 : RegionUnion : : )

1、签名中，RegionUnion中对象的个数和Region1一致，如果Region1含多个对象并且Region2只有一个对象，则Region1中每一个对象都和Region2 合并。

2、如果Region1只有1个对象，Region2有多个对象，相当于先将Region2合并，然后再和Region1合并，结果RegionUnion 中只有一个对象。

3、如果Region1有2个对象，Region2有多个对象，相当于先将Region2合并，然后再和Region1的每个对象逐个合并，结果RegionUnion 中有2个对象。

posted on 2017-02-22 21:21  xh6300  阅读(1407)  评论(0编辑  收藏  举报