请大家帮个忙,用java或c++实现

+++++++++                                                           +++
+++++++++                                                           +++
++++++++                                                            +++
+++++++                                                            ++++
++++++   ++                                                        ++++
+++++   ++                                                         ++++
 +++   ++                                                         +++++
 ++   ++                  +                                    +  +++++
 ++  ++           + ++++                                     ++  ++++++
 +++++    +         ++++     ++++++++                      +++   ++++++
 +++++   +         ++++++ ++++++++++                    +++++   +++++++
  +++             + +++++++++++++++                   +++++    ++++++++
  ++   +       + +++++++++++++++++                    +++     +++++++++
 +++  ++       ++++++++++++++++++                  ++        ++++++++++
 +   +++ +  +++++++++++++++++++                  +++        +++++++++++
 +  ++ +++ ++++++++++++++++++ +                 +++        ++++++++++++
 +  +  ++  ++++++++++++++++++ +                 ++++      +++++++++++++
 ++++ ++ +++++++++++++++++++++                   ++++   ++++++++++++++
 +++++  ++++++++++++++++++++++                   ++++   ++++++++++++++
++++++ +++++++++++++++++++++                     ++++   +++++++++++++ 
++++++++++++++++++++++++++                        ++++  +++++++++++++ 
+++  ++++++++++++++++++++                         ++++  ++++++++++++  
+++  ++++++++++++++++ ++                          ++++  ++++++++++++  
+   +++++++++++++++++++                           +++++ ++++++++++++  
+   +++++++++++++++++++                           +++++ +++++++++++   
  +++++++++++++++++++ +        +                  +++++ +++++++++++   
  ++++++++++++++++++++        +++++               +++++ +++++++++++   
 +++++++++++++++++++             ++++           +++++++  +++++++++    
++++++++++++++++++++       +++++++++++        +++++++++  +++++++++    
+++++++++++++++++++       ++++++++++ +       +++++++++++ +++++++++    
++++++++++++++++++       +++++++ +++++      ++++++++++++ ++++++++     
++++++++++++++++++       +++++++  +++++    +++++ +++++++ ++++++++     
+++++++++++++++++       +++++++    ++++    + ++  +++++++ ++++++++     
++++++++++++++++       +   +++      +++         ++++++++ +++++++      
+++++  ++++++++++     +      ++     +++       ++++++++++ +++++++      
++++++ +++++++++    +++               ++       +++++++++ +++++++      
++++++ ++++++++    ++++               ++        ++++++++ +++++++      
+++++ ++++++++     ++++               ++        ++++++++  +++++       
+++++++ +++++++   +++++                +        ++++++++  +++++       
+++++++  ++++    ++++++                +        ++++++++  +++++       
++++++++++++++   ++++++               ++         +++++++  ++++        
+++++++ + ++    +++++++               ++        ++++++++  ++++        
+++++++ +++++   ++++++++              ++         +++++++  ++++        
+++++ +++++    +++++++++           ++  +        ++++++++  +++         
++++++++++    ++++++++++           ++  ++       +++++++++  ++         
+++++ ++++   +++++++++++           +++++++      +++++++++  ++         
++++++++++   +++++++++++             ++++      ++++++++++  ++         
+ +++++  +  +++++++++++++                      ++++++++++  +          
+++++    + +++++++++++++                       ++++++++++  +          
+++++   +  ++++++++++++++                     +++++++++++  +          
 ++    ++ +++++++++++++++                     +++++++++++             
++     + +++++++++++++++++    +++  +++++ +++ +++++++++++++            
++    +  +++++++++++++++++    ++++++++++ ++  +++++++++++++            
+    +  +++++++++++++++++++    +++++        ++++++++++++++            
+      ++++++++++++++++++++      ++++       ++++++++++++++            
      +++++++++++++++++++++       ++++++   +++++++++++++++            
++   +++++++++++++++++++++++               +++++++++++++++            
++   +++++++++++++++++++++++              ++++++++++++++++            
+++ +++++++++++++++++++++++++             ++++++++++++++++            
 +++++++++++++++++++++++++++++            ++++++++++++++++            
    +++++++++++++++++++++++++++          +++++++++++++++++            
  +  ++++++++++++++++++++++++             ++++++++++++++++  ++        
+ ++  ++++++++++++++++++++++                 +++++++++++++    +++++   
++++   +++++++++++++++++++++++                ++++++++++++      +++++++
++   + ++++++++++++++++++++++                   ++++++++++        +++++
++   ++ +++++++++++++++++++++                    +++++++++          +++
+    + + ++++++++++++++++++++                      ++++++             
++   + +++++++++++++++++++++                       ++++++             
++   ++ +++++++++++++++++++                         +++++             
+++   ++ ++++++++++++++++++                          ++++             
+++   ++ +++++++++++++++++++                         ++++             
 

1.        Finding connected components in a binary image.

a)        An Union-Find data structure should be implemented as an abstract data type (a class in C++) with the following operations.

·           uandf(n): constructs an union-find data type with n elements, 1, 2, . . . , n.

·           make set(i): creates a new set whose only member (and thus representative) is i.

·           union sets(i,j): unites the dynamic sets that contains i and j, respectively, into a new set that is the union of these two sets.

·           find set(i): returns the representative of the set containing i.

·           final sets(): returns the total number of current sets, finalizes the current sets (make set() and union sets() will have no effect after this operation), and resets the representatives of the sets so that integers from 1 to final sets() will be used as representatives.

b)        Design and implement (a program) an algorithm to find the connected components in a binary image using Union-Find data structure in a).

An ASCII file containing a binary image is available (see girl.img and img readme) as the input of your program. The output of the program should be the following in this specified order:

1.        the input binary image,

2.        the connected component image where each component is labelled with a unique character,

3.        a list sorted by component size, where each line of the list contains the size and the label of a component,

4.        same as 2 with the connected component whose size equals to one removed.

关于图的说明:

File girl.img contains a 71 by 71 binary image in plain text.

In this file, a + means 1 and a space means 0. We only consider the connected components of 1.

The total number of components is less than 26. Therefore you can use letters from 'a' to 'z' to identify all the components.

We use 4 connectivity for +. Therefore ++ and + are considered connected.               

However +  and  + are not considered connected.

关于make(i)make xi a subset and assigns a name for the subset.

find set(i): returns the name of the subset that contains xi

union(i, j): combines subsets that contain xi and xj, say Si and Sj, into a new subset with a unique name( any name distinct from other names will).

   

转载于:https://www.cnblogs.com/ugvanxk/archive/2009/02/19/1393729.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值