mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Added example for region boundary merging
This commit is contained in:
@@ -23,29 +23,30 @@ import numpy as np
|
||||
def max_edge(g, src, dst, n):
|
||||
"""Callback to handle merging nodes by choosing maximum weight.
|
||||
|
||||
Returns either the weight between (`src`, `n`) or (`dst`, `n`)
|
||||
in `g` or the maximum of the two when both exist.
|
||||
Returns a dictionary with `"weight"` set as either the weight between
|
||||
(`src`, `n`) or (`dst`, `n`) in `graph` or the maximum of the two when
|
||||
both exist.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
g : RAG
|
||||
graph : RAG
|
||||
The graph under consideration.
|
||||
src, dst : int
|
||||
The vertices in `g` to be merged.
|
||||
The verices in `graph` to be merged.
|
||||
n : int
|
||||
A neighbor of `src` or `dst` or both.
|
||||
|
||||
Returns
|
||||
-------
|
||||
weight : float
|
||||
The weight between (`src`, `n`) or (`dst`, `n`) in `g` or the
|
||||
maximum of the two when both exist.
|
||||
|
||||
data : dict
|
||||
A dict with the `"weight"` attribute set the weight between
|
||||
(`src`, `n`) or (`dst`, `n`) in `graph` or the maximum of the two when
|
||||
both exist.
|
||||
"""
|
||||
|
||||
w1 = g[n].get(src, {'weight': -np.inf})['weight']
|
||||
w2 = g[n].get(dst, {'weight': -np.inf})['weight']
|
||||
return max(w1, w2)
|
||||
return {'weight': max(w1, w2)}
|
||||
|
||||
|
||||
def display(g, title):
|
||||
|
||||
Reference in New Issue
Block a user