def compute_dense_rag_table(volume): """ Find all voxel-level adjacencies in the volume, except for adjacencies to ID 0. Returns: dataframe with columns: ['label_a', 'label_b', 'forwardness', 'z', 'y', 'x', 'axis'] where ``label_a < label_b`` for all rows, and `forwardness` indicates whether label_a is on the 'left' (upper) or on the 'right' (lower) side of the voxel boundary. """ assert volume.dtype == np.uint32 rag = Rag(vigra.taggedView(volume, 'zyx')) # Edges are stored by axis -- concatenate them all. edges_z, edges_y, edges_x = rag.dense_edge_tables.values() del rag if len(edges_z) == len(edges_y) == len(edges_x) == 0: return None # No edges detected edges_z['axis'] = 'z' edges_y['axis'] = 'y' edges_x['axis'] = 'x' all_edges = list(filter(len, [edges_z, edges_y, edges_x])) edges_df = pd.concat(all_edges, ignore_index=True) edges_df.rename(columns={'sp1': 'label_a', 'sp2': 'label_b'}, inplace=True) del edges_df['edge_label'] # Filter: not interested in label 0 edges_df.query("label_a != 0 and label_b != 0", inplace=True) return edges_df
def rag(superpixels): return Rag(vigra.taggedView(superpixels, axistags="yxc").withAxes("yx"))