mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-07 11:28:14 +08:00
Renamed graph.py to rag.py
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import networkx as nx
|
||||
import rag
|
||||
cimport numpy as cnp
|
||||
import numpy as np
|
||||
|
||||
@@ -10,7 +10,7 @@ def construct_rag_meancolor_3d( img, arr):
|
||||
b = arr.shape[1]
|
||||
h = arr.shape[2]
|
||||
|
||||
g = nx.Graph()
|
||||
g = rag.RAG()
|
||||
|
||||
i = 0
|
||||
while i < l - 1:
|
||||
@@ -81,7 +81,7 @@ def construct_rag_meancolor_2d(img, arr):
|
||||
l = arr.shape[0]
|
||||
b = arr.shape[1]
|
||||
|
||||
g = nx.Graph()
|
||||
g = rag.RAG()
|
||||
|
||||
i = 0
|
||||
while i < l - 1:
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import networkx as nx
|
||||
import _construct
|
||||
from skimage import util
|
||||
|
||||
class RAG(nx.Graph):
|
||||
|
||||
def merge_nodes(i,j):
|
||||
if not self.has_edge(i, j):
|
||||
raise ValueError('Cant merge non adjacent nodes')
|
||||
|
||||
# print "before ",self.order()
|
||||
for x in self.neighbors(i):
|
||||
if x == j:
|
||||
continue
|
||||
w1 = self.get_edge_data(x, i)['weight']
|
||||
w2 = -1
|
||||
if self.has_edge(x, j):
|
||||
w2 = self.get_edge_data(x, j)['weight']
|
||||
|
||||
w = max(w1, w2)
|
||||
|
||||
self.add_edge(x, j, weight=w)
|
||||
|
||||
self.node[j]['labels'] += self.node[i]['labels']
|
||||
self.remove_node(i)
|
||||
|
||||
def rag_meancolor(img,labels):
|
||||
|
||||
img = util.img_as_ubyte(img)
|
||||
if img.ndim == 3 :
|
||||
return _construct.construct_rag_meancolor_3d(img,labels)
|
||||
elif img.ndim == 2 :
|
||||
return _construct.construct_rag_meancolor_2d(img,labels)
|
||||
else :
|
||||
raise ValueError("Image dimension not supported")
|
||||
@@ -0,0 +1,10 @@
|
||||
import numpy as np
|
||||
|
||||
def test_threshold_cut():
|
||||
arr = np.array((100,100,3),dtype='uint8')
|
||||
arr[:50,:50] = 0
|
||||
arr[:50,50:] = 1
|
||||
arr[50:,50:] = 2
|
||||
arr[50:,50:] = 3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user