Skip to content

Commit 24472de

Browse files
committed
Changes:
1. Edits in agg_recursion and vect_edge.
1 parent f054597 commit 24472de

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

frame_2D_alg/agg_recursion.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ def cross_comp(root): # breadth-first node_,link_ cross-comp, connect.clusterin
2424
mlay = CH().add_tree([L.derH for L in L_]); H=root.derH; mlay.root=H; H.Et += mlay.Et; H.lft = [mlay]
2525
pL_ = {l for n in N_ for l,_ in get_rim(n, fd=0)}
2626
if len(pL_) > ave_L:
27-
cluster_N_([root], pL_, fd=0) # optional divisive clustering, calls centroid and higher connect.clustering
27+
# initial root is not a list
28+
cluster_N_(root, pL_, fd=0) # optional divisive clustering, calls centroid and higher connect.clustering
2829
# dfork
2930
if val_(Et, mEt=Et,fo=1) > 0: # same root for L_, root.link_ was compared in root-forming for alt clustering
3031
for L in L_:
31-
L.extH, L.root, L.Et, L.mL_t, L.rimt, L.aRad, L.visited_ = CH(),[root],copy(L.derH.Et),[[],[]], [[],[]], 0,[L]
32+
L.extH, L.root, L.Et, L.mL_t, L.rimt, L.aRad, L.visited_ = CH(),root,copy(L.derH.Et),[[],[]], [[],[]], 0,[L]
3233
lN_,lL_,dEt = comp_link_(L_,Et)
3334
if val_(dEt, mEt=Et, fo=1) > 0:
3435
dlay = CH().add_tree([L.derH for L in lL_]); dlay.root=H; H.Et += dlay.Et; H.lft += [dlay]
3536
plL_ = {l for n in lN_ for l,_ in get_rim(n, fd=1)}
3637
if len(plL_) > ave_L:
37-
cluster_N_([root], plL_, fd=1)
38+
cluster_N_(root, plL_, fd=1)
3839

3940
feedback(root) # add root derH to higher roots derH
4041

@@ -69,15 +70,21 @@ def cluster_N_(root_, L_, fd, nest=0): # top-down segment L_ by >ave ratio of L
6970
n.fin = 0; _eN_ += [n]
7071
G_ += [sum2graph(root_, [list({*node_}),list({*link_}), et, min_dist], fd, nest)]
7172
# higher root_ assign to all sub_G nodes
73+
74+
# this is moved here now since deeper subs are formed later
75+
hroot = root_[-1] if isinstance(root_,list) else root_ # higher root
76+
if fd: hroot.subL_ = G_
77+
else: hroot.subG_ = G_
78+
7279
for G in G_: # breadth-first
7380
sub_L_ = {l for n in G.node_ for l,_ in get_rim(n,fd) if l.dist < min_dist}
7481
if len(sub_L_) > ave_L:
7582
Et = np.sum([sL.derH.Et for sL in sub_L_],axis=0); Et[3]+=nest
7683
if val_(Et, fo=1) > 0:
84+
if not isinstance(root_,list): root_ = [root_] # first conversion when nest == 1
7785
cluster_N_(root_+[G], sub_L_, fd, nest+1) # sub-cluster shorter links, nest in G.subG_
7886
# root_ += [root] / dist segment
79-
root_[-1].subG_ = G_
80-
cluster_C_(root_[-1])
87+
cluster_C_(hroot)
8188

8289
''' Hierarchical clustering should alternate between two phases: generative via connectivity and compressive via centroid.
8390

frame_2D_alg/comp_slice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
from frame_blobs import CBase, frame_blobs_root, intra_blob_root, imread, unpack_blob_
3-
from frame_2D_alg.slice_edge import CP, slice_edge, comp_angle, ave_G
3+
from slice_edge import CP, slice_edge, comp_angle, ave_G
44

55
'''
66
comp_slice traces edge axis by cross-comparing vertically adjacent Ps: horizontal slices across an edge blob.

frame_2D_alg/vect_edge.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,9 @@ def get_rim(N,fd): return N.rimt[0] + N.rimt[1] if fd else N.rim # add nesting
425425
def sum2graph(root, grapht, fd, nest): # sum node and link params into graph, aggH in agg+ or player in sub+
426426

427427
node_, link_, Et = grapht[:3]
428-
fsub = len(grapht) == 5 # called from divisive cluster_N
429-
graph = CG(fd=fd, Et=Et*icoef, root=root[-1] if fsub else root, node_=node_, link_=link_, rng=nest)
428+
graph = CG(fd=fd, Et=Et*icoef, root=root[-1] if isinstance(root,list) else root, node_=node_, link_=link_, rng=nest) # in cluster_N_, root is not a list when nest == 0
430429
# arg Et is internalized; only direct root assign before clustering
431-
if fsub: # called from cluster_N
432-
minL, subG_ = grapht[3:]
433-
if fd: graph.subL_ = subG_
434-
else: graph.subG_ = subG_
435-
graph.minL = minL
430+
if len(grapht)==4: graph.minL = grapht[3] # called from cluster_N
436431
yx = np.array([0,0])
437432
derH = CH(root=graph)
438433
for N in node_:
@@ -456,18 +451,20 @@ def sum2graph(root, grapht, fd, nest): # sum node and link params into graph, a
456451
yx = np.divide(yx,L); graph.yx = yx
457452
# ave distance from graph center to node centers:
458453
graph.aRad = sum([np.hypot( *np.subtract(yx, N.yx)) for N in node_]) / L
459-
if fd and val_(Et, mEt=root.Et) > 0: # strong dgraph
460-
altG_ = [] # mGs overlapping dG
461-
for L in node_:
462-
for n in L.nodet: # map root mG
463-
if isinstance(n.root,list):
464-
for G in n.root[1:]: # skip the first root: frame or edge
465-
if L.dist >= G.minL: # same dist segment root
466-
mG = G; break
467-
else: mG = n.root
468-
if mG not in altG_:
469-
mG.altG = sum_G_([mG.altG, graph])
470-
altG_ += [mG]
454+
if fd: # strong dgraph
455+
mEt = np.sum([r.Et for r in root[1:]],axis=1) if isinstance(root, list) else (root.Et if isinstance(root, CG) else [.0,.0,.0,.0])
456+
if val_(Et, mEt=mEt):
457+
altG_ = [] # mGs overlapping dG
458+
for L in node_:
459+
for n in L.nodet: # map root mG
460+
if isinstance(n.root,list):
461+
for G in n.root[1:]: # skip the first root: frame or edge
462+
if L.dist >= G.minL: # same dist segment root
463+
mG = G; break
464+
else: mG = n.root
465+
if mG not in altG_:
466+
mG.altG = sum_G_([mG.altG, graph])
467+
altG_ += [mG]
471468
feedback(graph) # recursive root.derH.add_fork(graph.derH)
472469
return graph
473470

0 commit comments

Comments
 (0)