mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-14 12:50:39 +08:00
Improved test case and removed duplicate test
This commit is contained in:
@@ -34,13 +34,12 @@ def _weight_mean_color(graph, src, dst, n):
|
||||
The absolute difference of the mean color between node `dst` and `n`.
|
||||
"""
|
||||
|
||||
#print 'merging
|
||||
diff = graph.node[dst]['mean color'] - graph.node[n]['mean color']
|
||||
diff = np.linalg.norm(diff)
|
||||
return diff
|
||||
|
||||
|
||||
def _pre_merge_mean_color(graph, src, dst):
|
||||
def merge_mean_color(graph, src, dst):
|
||||
"""Callback called before merging two nodes of a mean color distance graph.
|
||||
|
||||
This method computes the mean color of `dst`.
|
||||
@@ -58,44 +57,13 @@ def _pre_merge_mean_color(graph, src, dst):
|
||||
graph.node[dst]['pixel count'])
|
||||
|
||||
|
||||
def merge_hierarchical_mean_color(labels, rag, thresh, rag_copy=True,
|
||||
in_place_merge=False):
|
||||
"""Perform hierarchical merging of a color distance RAG.
|
||||
|
||||
Greedily merges the most similar pair of nodes until no edges lower than
|
||||
`thresh` remain.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
labels : ndarray
|
||||
The array of labels.
|
||||
rag : RAG
|
||||
The Region Adjacency Graph.
|
||||
thresh : float
|
||||
Regions connected by an edge with weight smaller than `thresh` are
|
||||
merged.
|
||||
rag_copy : bool, optional
|
||||
If set, the RAG copied before modifying.
|
||||
in_place_merge : bool, optional
|
||||
If set, the nodes are merged in place. Otherwise, a new node is
|
||||
created for each merge.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage import data, graph, segmentation
|
||||
>>> img = data.coffee()
|
||||
>>> labels = segmentation.slic(img)
|
||||
>>> rag = graph.rag_mean_color(img, labels)
|
||||
>>> new_labels = graph.merge_hierarchical_mean_color(labels, rag, 40)
|
||||
"""
|
||||
return graph.merge_hierarchical(labels, rag, thresh, rag_copy,
|
||||
in_place_merge, _pre_merge_mean_color,
|
||||
_weight_mean_color)
|
||||
|
||||
img = data.coffee()
|
||||
labels = segmentation.slic(img, compactness=30, n_segments=400)
|
||||
g = graph.rag_mean_color(img, labels)
|
||||
labels2 = merge_hierarchical_mean_color(labels, g, 40)
|
||||
|
||||
labels2 = graph.merge_hierarchical(labels, g, 40, False, True,
|
||||
merge_mean_color, _weight_mean_color)
|
||||
|
||||
g2 = graph.rag_mean_color(img, labels2)
|
||||
|
||||
out = color.label2rgb(labels2, img, kind='avg')
|
||||
|
||||
Reference in New Issue
Block a user