Skip to content

Commit 3cb4aef

Browse files
committed
Changes:
1. Edits in vect_edge and agg_recursion.
1 parent f2453c5 commit 3cb4aef

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

frame_2D_alg/agg_recursion.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import sys
2-
sys.path.append("..")
1+
32
import numpy as np
43
from copy import copy, deepcopy
54
from functools import reduce
@@ -42,7 +41,7 @@ def cross_comp(root): # breadth-first node_,link_ cross-comp, connect.clusterin
4241
def convert_L_(L_, root):
4342
for L in L_:
4443
L.extH, L.mL_t, L.rimt, L.aRad, L.visited_ = CH(), [[],[]], [[],[]], 0, [L]
45-
L.root = [L.root,root]; L.Et = copy(L.derH.Et) # convert to root_
44+
L.root = [root]; L.Et = copy(L.derH.Et) # convert to root_ (L.root should be empty here? Because all new L doesn't have root assigned before they become node)
4645

4746

4847
def cluster_N_(root_, L_, fd, nest=0): # top-down segment L_ by >ave ratio of L.dists
@@ -184,7 +183,7 @@ def centroid_cluster(N): # refine and extend cluster with extN_
184183

185184

186185
if __name__ == "__main__":
187-
image_file = '../images/raccoon_eye.jpeg'
186+
image_file = './images/raccoon_eye.jpeg'
188187
image = imread(image_file)
189188
frame = frame_blobs_root(image)
190189
intra_blob_root(frame)

frame_2D_alg/comp_slice.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import numpy as np
2-
import sys
3-
sys.path.append("..")
42
from frame_blobs import CBase, frame_blobs_root, intra_blob_root, imread, unpack_blob_
53
from slice_edge import CP, slice_edge, comp_angle, ave_G, ave_I
64
'''
@@ -225,8 +223,8 @@ def min_dist(a, b, pad=0.5):
225223

226224
if __name__ == "__main__":
227225

228-
# image_file = '../images//raccoon_eye.jpeg'
229-
image_file = '../images//toucan_small.jpg'
226+
# image_file = './images//raccoon_eye.jpeg'
227+
image_file = './images//toucan_small.jpg'
230228
image = imread(image_file)
231229

232230
frame = frame_blobs_root(image)

frame_2D_alg/slice_edge.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from collections import defaultdict
33
from itertools import combinations
44
from math import atan2, cos, floor, pi
5-
import sys
6-
sys.path.append("..")
75
from frame_blobs import frame_blobs_root, intra_blob_root, CBase, imread, unpack_blob_
86
'''
97
In natural images, objects look very fuzzy and frequently interrupted, only vaguely suggested by initial blobs and contours.
@@ -207,8 +205,8 @@ def xsegs(yx1, yx2, yx3, yx4):
207205

208206
if __name__ == "__main__":
209207

210-
# image_file = '../images//raccoon_eye.jpeg'
211-
image_file = '../images//toucan_small.jpg'
208+
# image_file = './images//raccoon_eye.jpeg'
209+
image_file = './images//toucan_small.jpg'
212210
image = imread(image_file)
213211

214212
frame = frame_blobs_root(image)

frame_2D_alg/vect_edge.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
sys.path.append("..")
31
from frame_blobs import CBase, frame_blobs_root, intra_blob_root, imread, unpack_blob_
42
from slice_edge import slice_edge, comp_angle, ave_G
53
from comp_slice import comp_slice, comp_latuple, comp_md_
@@ -258,7 +256,7 @@ def cluster_PP_(edge, fd):
258256
_eN_ = eN_
259257
Gt = [node_,link_,et]; Gt_ += [Gt]
260258
# convert select Gt+minL+subG_ to CGs:
261-
subG_ = [sum2graph(edge, [node_,link_,et], fd, nest=1) for node_,link_,et in Gt_ if val_(et) > 0]
259+
subG_ = [sum2graph(edge, [node_,link_,et], fd, nest=0) for node_,link_,et in Gt_ if val_(et) > 0] # nest should be 0 here?
262260
if subG_:
263261
if fd: edge.subL_ = subG_
264262
else: edge.subG_ = subG_ # higher aggr, mediated access to init edge.subG_
@@ -273,12 +271,12 @@ def cluster_PP_(edge, fd):
273271
cluster_PP_(edge, fd=0)
274272
if val_(Et, mEt=Et, fo=1) > 0: # likely not from the same links
275273
for L in L_:
276-
L.extH, L.root, L.mL_t, L.rimt, L.aRad, L.visited_, L.Et = CH(), [edge], [[],[]], [[],[]], 0, [L], copy(L.derH.Et)
274+
L.extH, L.root, L.mL_t, L.rimt, L.aRad, L.visited_, L.Et = CH(), None, [[],[]], [[],[]], 0, [L], copy(L.derH.Et)
277275
# comp dPP_:
278276
lN_,lL_,dEt = comp_link_(L_, Et)
279277
if val_(dEt, fo=1) > 0:
280278
dlay = CH().add_tree([L.derH for L in lL_])
281-
H = edge.derH; dlay.root=H; H.Et += dlay.Et; H.lft += [dlay]
279+
dlay.root=H; H.Et += dlay.Et; H.lft += [dlay]
282280
if len(lN_) > ave_L:
283281
cluster_PP_(edge, fd=1)
284282

@@ -451,7 +449,7 @@ def sum2graph(root, grapht, fd, nest): # sum node and link params into graph, a
451449
graph.Et += N.Et * icoef ** 2 # deeper, lower weight
452450
if nest:
453451
if nest==1: N.root = [N.root] # initial conversion
454-
N.root += root + [graph] # root is root_ in distance-layered cluster_N_
452+
N.root = root + [graph] # root is root_ in distance-layered cluster_N_ (should be = root + [graph] here? Because root will be incremented with each new nesting)
455453
else: N.root = graph # single root
456454
# sum link_ derH:
457455
derLay = CH().add_tree([link.derH for link in link_],root=graph) # root added in copy_ within add_tree
@@ -462,15 +460,17 @@ def sum2graph(root, grapht, fd, nest): # sum node and link params into graph, a
462460
yx = np.divide(yx,L); graph.yx = yx
463461
# ave distance from graph center to node centers:
464462
graph.aRad = sum([np.hypot( *np.subtract(yx, N.yx)) for N in node_]) / L
465-
# for CG nodes only:
466-
if isinstance(N,CG) and fd:
463+
# for CG nodes only: (we still need to assign this in d fork? Because in d fork, N is always a CL)
464+
if fd:
467465
# assign alt graphs from d graph, after both m and d graphs are formed
468-
for node in node_:
469-
mgraph = node.root_[-1]
470-
# altG summation below is still buggy with current add_tree
471-
if mgraph:
472-
mgraph.altG = sum_G_([mgraph.altG, graph]) # bilateral sum?
473-
graph.altG = sum_G_([graph.altG, mgraph])
466+
for L in node_:
467+
summed = [] # multiple nodets may have a same root, so we need this to check and sum them only once
468+
for node in L.nodet:
469+
# in agg+, nodes has multiple nesting layers' root
470+
for mgraph in node.root[1:] if isinstance(node.root, list) else [node.root]: # skip the first root: frame or edge
471+
if mgraph not in summed:
472+
summed += [mgraph]
473+
mgraph.altG = sum_G_([mgraph.altG, graph])
474474

475475
feedback(graph) # recursive root.derH.add_fork(graph.derH)
476476
return graph
@@ -501,7 +501,7 @@ def sum_G_(node_):
501501
return G
502502

503503
if __name__ == "__main__":
504-
image_file = '../images/raccoon_eye.jpeg'
504+
image_file = './images/raccoon_eye.jpeg'
505505
image = imread(image_file)
506506
frame = frame_blobs_root(image)
507507
intra_blob_root(frame)

0 commit comments

Comments
 (0)