def main(data):
    forest = []
    for item in data:
        forest.append(node(item))
    disjoin_set.union(forest[1],forest[2])
    disjoin_set.union(forest[3],forest[4])
    disjoin_set.union(forest[1],forest[4])
    for item in forest:
        if item==disjoin_set.find(item):
            print "item is:"+str(item)+"  value is:"+str(item.value)+"  parent is:"+str(item.parent)
def main(data):
    forest = []
    for item in data:
        forest.append(node(item))
    disjoin_set.union(forest[1], forest[2])
    disjoin_set.union(forest[3], forest[4])
    disjoin_set.union(forest[1], forest[4])
    for item in forest:
        if item == disjoin_set.find(item):
            print "item is:" + str(item) + "  value is:" + str(
                item.value) + "  parent is:" + str(item.parent)
Example #3
0
 def grap_base_seg(e_set,k):
     '''
     Here we will implimention the graph based iamge segment method
     which proposed by Pedro F.Felzenszwalb and Daniel P.Huttenlocher
     in the paper "Efficient Graph-Based Image Segmentation"
     This method based on Kruskal's algorithm and use the disjoin set
     as the data structure
     The interpretation of arguments:
         e_set : is the  list of edge's weight, and it saved in a 
         symmetric matrix. And the index is the position of pixel 
         which ordered by column first, raw second.As the matrix will
         be very sparse, so here use link chain to store
         k : is the coefficent multiplier
     The result will stored in the disjoin set
     '''
     #Zero: order the edge in e_set by weight in Ascending order        
     ord_e = []
     for i in range(0,len(e_set)):
         for j in range(0,len(e_set[i])):
             ord_e.append(edge_node(i,e_set[i][j][0],e_set[i][j][1]))
     ord_e.sort(cmp_e)
     #First: initialize the segment,v_set will maintains the result
     v_set = []
     for raw in range(0,len(e_set)):
         v_set.append(vertex_node(0))
     #Second, split loop, for each edge do the follow
     for e in ord_e:
         region1 = disjoin_set.find(v_set[e.v1])
         region2 = disjoin_set.find(v_set[e.v2])
         if region1!=region2:
             Int1 = region1.value +  k/region1.coefficient
             Int2 = region2.value +  k/region2.coefficient
             Int = Int1
             if Int1 > Int2:
                 Int = Int2
             if e.w <= Int: #then the two region can be merged
                 region = disjoin_set.union(region1,region2)
                 region.value = e.w #the max w in MST of region
                 region.coefficient = region1.coefficient + region2.coefficient
         else:
             continue
     #Third, return the result
     return v_set
Example #4
0
 def grap_base_seg(e_set, k):
     """
     Here we will implimention the graph based iamge segment method
     which proposed by Pedro F.Felzenszwalb and Daniel P.Huttenlocher
     in the paper "Efficient Graph-Based Image Segmentation"
     This method based on Kruskal's algorithm and use the disjoin set
     as the data structure
     The interpretation of arguments:
         e_set : is the  list of edge's weight, and it saved in a 
         symmetric matrix. And the index is the position of pixel 
         which ordered by column first, raw second.As the matrix will
         be very sparse, so here use link chain to store
         k : is the coefficent multiplier
     The result will stored in the disjoin set
     """
     # Zero: order the edge in e_set by weight in Ascending order
     ord_e = []
     for i in range(0, len(e_set)):
         for j in range(0, len(e_set[i])):
             ord_e.append(edge_node(i, e_set[i][j][0], e_set[i][j][1]))
     ord_e.sort(cmp_e)
     # First: initialize the segment,v_set will maintains the result
     v_set = []
     for raw in range(0, len(e_set)):
         v_set.append(vertex_node(0))
     # Second, split loop, for each edge do the follow
     for e in ord_e:
         region1 = disjoin_set.find(v_set[e.v1])
         region2 = disjoin_set.find(v_set[e.v2])
         if region1 != region2:
             Int1 = region1.value + k / region1.coefficient
             Int2 = region2.value + k / region2.coefficient
             Int = Int1
             if Int1 > Int2:
                 Int = Int2
             if e.w <= Int:  # then the two region can be merged
                 region = disjoin_set.union(region1, region2)
                 region.value = e.w  # the max w in MST of region
                 region.coefficient = region1.coefficient + region2.coefficient
         else:
             continue
     # Third, return the result
     return v_set