class UFGraphBasedSegment: def __init__(self, size, tau_k, root_dict): self.uf = UnionFind(size, root_dict) self.tau_k = tau_k ''' Merge two components. @param id1 : component id to merge @param id2 : component id to merge @param edge_value : difference value of intertested edge @return bool : TRUE if merging two components, else FALSE ''' def merge(self, id1, id2, edge_value): root_node1 = self.uf.get_root(id1) root_node2 = self.uf.get_root(id2) if edge_value < self.mint(root_node1, root_node2): self.uf.union(id1=id1, id2=id2, edge_value=edge_value) ''' Calculate the minimum internal difference between two components. @param id1 : One of two components to calculate minimum internal difference of boundary @param id2 : One of two components to calculate minimum internal difference of boundary @param mcl : Merged Component List @return float : minimum internal difference between two components ''' def mint(self, r1, r2): return min(r1.get_min_dif() + self.tau(r1), r2.get_min_dif() + self.tau(r2)) ''' Calculate threashold based on the size of the component. @param mc : merged component to calculate the threashold @return float : threashold based on the size of the component ''' def tau(self, root): return float(self.tau_k / root.get_size()) ''' Get union find. @return UnionFind : union find tree ''' def get_union_find(self): return self.uf
class UFGraphBasedSegment: def __init__(self, size, tau_k, root_dict): self.uf = UnionFind(size, root_dict) self.tau_k = tau_k ''' Merge two components. @param id1 : component id to merge @param id2 : component id to merge @param edge_value : difference value of intertested edge @return bool : TRUE if merging two components, else FALSE ''' def merge(self, id1, id2, edge_value): root_node1 = self.uf.get_root(id1) root_node2 = self.uf.get_root(id2) if edge_value < self.mint(root_node1, root_node2): self.uf.union(id1=id1, id2=id2, edge_value=edge_value) ''' Calculate the minimum internal difference between two components. @param id1 : One of two components to calculate minimum internal difference of boundary @param id2 : One of two components to calculate minimum internal difference of boundary @param mcl : Merged Component List @return float : minimum internal difference between two components ''' def mint(self, r1, r2): return min(r1.get_min_dif()+self.tau(r1), r2.get_min_dif()+self.tau(r2)) ''' Calculate threashold based on the size of the component. @param mc : merged component to calculate the threashold @return float : threashold based on the size of the component ''' def tau(self, root): return float(self.tau_k / root.get_size()) ''' Get union find. @return UnionFind : union find tree ''' def get_union_find(self): return self.uf