Renamed graph.py to rag.py

This commit is contained in:
Vighnesh Birodkar
2014-06-19 02:50:24 +05:30
parent 53077c9f22
commit a6c9a5a2a7
3 changed files with 48 additions and 3 deletions
+3 -3
View File
@@ -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:
+35
View File
@@ -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")
+10
View File
@@ -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