def cut_threshold(labels, rag, thresh, in_place=True):
 if (not in_place):
  rag = rag.copy()
 to_remove = [(x, y) for (x, y, d) in rag.edges_iter(data=True) if (d['weight'] >= thresh)]
 rag.remove_edges_from(to_remove)
 comps = nx.connected_components(rag)
 map_array = np.arange((labels.max() + 1), dtype=labels.dtype)
 for (i, nodes) in enumerate(comps):
  for node in nodes:
   for label in rag.node[node]['labels']:
    map_array[label] = i
 return map_array[labels]

def cut_threshold ( labels , rag , thresh , in_place = True ) : if ( not in_place ) : rag = rag . copy ( ) to_remove = [ ( x , y ) for ( x , y , d ) in rag . edges_iter ( data = True ) if ( d [ 'weight' ] >= thresh ) ] rag . remove_edges_from ( to_remove ) comps = nx . connected_components ( rag ) map_array = np . arange ( ( labels . max ( ) + 1 ) , dtype = labels . dtype ) for ( i , nodes ) in enumerate ( comps ) : for node in nodes : for label in rag . node [ node ] [ 'labels' ] : map_array [ label ] = i return map_array [ labels ]
combine regions separated by weight less than threshold .