From 850f835114881b7ce179f322bb588c950461ae63 Mon Sep 17 00:00:00 2001 From: Vighnesh Birodkar Date: Mon, 16 Jun 2014 22:17:13 +0530 Subject: [PATCH] Docs formatting --- skimage/graph/graph_cut.py | 18 +++++++++--------- skimage/graph/rag.py | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/skimage/graph/graph_cut.py b/skimage/graph/graph_cut.py index 939681af..0f28b453 100644 --- a/skimage/graph/graph_cut.py +++ b/skimage/graph/graph_cut.py @@ -1,11 +1,12 @@ import networkx as nx import numpy as np + def threshold_cut(label, rag, thresh): """Combines regions seperated by weight less than threshold. Given an image's labels and its RAG, outputs new labels by - combining regions whose nodes are seperated by a weight less + combining regions whose nodes are seperated by a weight less than the given threshold. Parameters @@ -14,7 +15,7 @@ def threshold_cut(label, rag, thresh): The array of labels. rag : RAG The region adjacency graph. - thresh : float + thresh : float The threshold, regions with edge weights less than this are combined. @@ -23,19 +24,18 @@ def threshold_cut(label, rag, thresh): out : (width, height, 3) or (width, height, depth, 3) ndarray The new labelled array. """ - to_remove = [(x,y) for x,y,d in rag.edges_iter(data = True) if d['weight'] >= thresh] + 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) out = np.copy(label) - for i, nodes in enumerate(comps) : - - for node in nodes : - for l in rag.node[node]['labels'] : + for i, nodes in enumerate(comps): + + for node in nodes: + for l in rag.node[node]['labels']: out[label == l] = i - return out diff --git a/skimage/graph/rag.py b/skimage/graph/rag.py index 44ec76f9..2cf353de 100644 --- a/skimage/graph/rag.py +++ b/skimage/graph/rag.py @@ -2,16 +2,18 @@ import networkx as nx import _construct from skimage import util + class RAG(nx.Graph): + """ The class for holding the Region Adjacency Graph (RAG). Each region is a contiguous set of pixels in an image, usuall - sharing some common property.Adjacent regions have an edge + sharing some common property.Adjacent regions have an edge between their corresponding nodes. """ - def merge_nodes(self,i,j): + def merge_nodes(self, i, j): """Merges nodes `i` and `j`. The new combined node is adjacent to all the neighbors of `i` @@ -43,7 +45,7 @@ class RAG(nx.Graph): self.add_edge(x, j, weight=w) - self.node[j]['labels'] += self.node[i]['labels'] + self.node[j]['labels'] += self.node[i]['labels'] self.remove_node(i) @@ -70,9 +72,9 @@ def rag_meancolor(img, labels): """ img = util.img_as_ubyte(img) - if img.ndim == 4 : - return _construct.construct_rag_meancolor_3d(img,labels) - elif img.ndim == 3 : - return _construct.construct_rag_meancolor_2d(img,labels) - else : + if img.ndim == 4: + return _construct.construct_rag_meancolor_3d(img, labels) + elif img.ndim == 3: + return _construct.construct_rag_meancolor_2d(img, labels) + else: raise ValueError("Image dimension not supported")