mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-02 13:03:48 +08:00
Docs formatting
This commit is contained in:
@@ -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
|
||||
|
||||
+10
-8
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user