mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-12 15:16:57 +08:00
Got doctest to pass and docstring changes
This commit is contained in:
@@ -4,10 +4,10 @@ Region Adjacency Graphs
|
||||
=======================
|
||||
|
||||
This example demonstrates the use of the `merge_nodes` function of a Region
|
||||
Adjacency Graph (RAG).The `RAG` class represents a undirected weighted graph
|
||||
which inherits from `networkx.graph` class. When a new node is formed by merging
|
||||
two nodes, the edge weight of all the edges incident on the resulting node can
|
||||
be updated by a user defined function `weight_func`.
|
||||
Adjacency Graph (RAG). The `RAG` class represents a undirected weighted graph
|
||||
which inherits from `networkx.graph` class. When a new node is formed by
|
||||
merging two nodes, the edge weight of all the edges incident on the resulting
|
||||
node can be updated by a user defined function `weight_func`.
|
||||
|
||||
The default behaviour is to use the smaller edge weight in case of a conflict.
|
||||
The example below also shows how to use a custom function to select the larger
|
||||
|
||||
@@ -28,8 +28,9 @@ def min_weight(graph, src, dst, n):
|
||||
"""
|
||||
|
||||
# cover the cases where n only has edge to either `src` or `dst`
|
||||
w1 = graph[n].get(src, {'weight': np.inf})['weight']
|
||||
w2 = graph[n].get(dst, {'weight': np.inf})['weight']
|
||||
default = {'weight': np.inf}
|
||||
w1 = graph[n].get(src, default)['weight']
|
||||
w2 = graph[n].get(dst, default)['weight']
|
||||
return min(w1, w2)
|
||||
|
||||
|
||||
@@ -55,7 +56,9 @@ class RAG(nx.Graph):
|
||||
Function to decide edge weight of edges incident on the new node.
|
||||
For each neighbor `n` for `src and `dst`, `weight_func` will be
|
||||
called as follows: `weight_func(src, dst, n, *extra_arguments,
|
||||
**extra_keywords)`
|
||||
**extra_keywords)`. `src`, `dst` and `n` are IDs of vertices in a
|
||||
.. py:class:: RAG object which is in turn a subclass of
|
||||
`networkx.Graph`.
|
||||
extra_arguments : sequence, optional
|
||||
The sequence of extra positional arguments passed to
|
||||
`weight_func`.
|
||||
@@ -138,7 +141,7 @@ def rag_mean_color(image, labels, connectivity=2):
|
||||
>>> from skimage import data, graph, segmentation
|
||||
>>> img = data.lena()
|
||||
>>> labels = segmentation.slic(img)
|
||||
>>> rag = graph.rag_meancolor(img, labels)
|
||||
>>> rag = graph.rag_mean_color(img, labels)
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
@@ -3,8 +3,9 @@ from skimage import graph
|
||||
|
||||
|
||||
def max_edge(g, src, dst, n):
|
||||
w1 = g[n].get(src, {'weight': -np.inf})['weight']
|
||||
w2 = g[n].get(dst, {'weight': -np.inf})['weight']
|
||||
default = {'weight': -np.inf}
|
||||
w1 = g[n].get(src, default)['weight']
|
||||
w2 = g[n].get(dst, default)['weight']
|
||||
return max(w1, w2)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user