13
13
prefix _ denotes prior of two same-name variables, multiple _s for relative precedence
14
14
postfix _ denotes array of same-name elements, multiple _s is nested array
15
15
capitalized vars are summed small-case vars
16
+
17
+ Each agg+ cycle forms higher-composition complemented graphs G.altG_ in cluster_N_ and refines them in cluster_C_:
18
+ cross_comp -> cluster_N_ -> cluster_C -> cross_comp...
16
19
'''
17
20
18
- def cross_comp (root ): # breadth-first node_,link_ cross-comp, connect.clustering, recursion
21
+ def cross_comp (root , nest = 0 ): # breadth-first node_,link_ cross-comp, connect.clustering, recursion
19
22
20
23
N_ ,L_ ,Et = comp_node_ (root .node_ ) # cross-comp exemplars, extrapolate to their node_s
21
24
# mfork
22
25
if val_ (Et , fo = 1 ) > 0 :
23
26
mlay = CH ().add_tree ([L .derH for L in L_ ]); H = root .derH ; mlay .root = H ; H .Et += mlay .Et ; H .lft = [mlay ]
24
27
pL_ = {l for n in N_ for l ,_ in get_rim (n , fd = 0 )}
25
28
if len (pL_ ) > ave_L :
26
- cluster_N_ (root , pL_ , fd = 0 ) # nested distance clustering, calls centroid and higher connect.clustering
29
+ cluster_N_ (root , pL_ , nest , fd = 0 ) # nested distance clustering, calls centroid and higher connect.clustering
27
30
# dfork
28
31
if val_ (Et , mEt = Et , fo = 1 ) > 0 : # same root for L_, root.link_ was compared in root-forming for alt clustering
29
32
for L in L_ :
@@ -33,12 +36,12 @@ def cross_comp(root): # breadth-first node_,link_ cross-comp, connect.clusterin
33
36
dlay = CH ().add_tree ([L .derH for L in lL_ ]); dlay .root = H ; H .Et += dlay .Et ; H .lft += [dlay ]
34
37
plL_ = {l for n in lN_ for l ,_ in get_rim (n , fd = 1 )}
35
38
if len (plL_ ) > ave_L :
36
- cluster_N_ (root , plL_ , fd = 1 )
39
+ cluster_N_ (root , plL_ , nest , fd = 1 )
37
40
38
- combine_altG__ (root ) # cross-comp | sum contour altG_ to altG
41
+ comb_altG_ (root ) # combine node altG_( contour) by sum,cross-comp -> CG altG
39
42
cluster_C_ (root ) # get (G,altG) exemplars, altG_ may reinforce G by borrowing from extended surround?
40
43
41
- def cluster_N_ (root , L_ , fd , nest = 0 ): # top-down segment L_ by >ave ratio of L.dists
44
+ def cluster_N_ (root , L_ , nest , fd ): # top-down segment L_ by >ave ratio of L.dists
42
45
43
46
L_ = sorted (L_ , key = lambda x : x .dist ) # shorter links first
44
47
while L_ :
@@ -91,7 +94,7 @@ def centroid(dnode_, node_, C=None): # sum|subtract and average Rim nodes
91
94
92
95
if C is None :
93
96
C ,A , fC = CG (),CG (), 0
94
- C .M ,C .L , A .M ,A .L = 0 ,0 ,0 ,0 # setattr
97
+ C .M ,C .L , A .M ,A .L = 0 ,0 ,0 ,0 # centroid setattr
95
98
else :
96
99
A , fC = C .altG_ , 1
97
100
sum_G_ (C , dnode_ , fc = 1 ) # exclude extend_box and sum extH
@@ -176,28 +179,26 @@ def sum_G_(G, node_, fc=0):
176
179
for n in node_ :
177
180
if fc :
178
181
s = n .sign ; n .sign = 1 # single-use
179
- else : s = 1
180
182
G .latuple += n .latuple * s ; G .vert += n .vert * s
181
183
G .Et += n .Et * s ; G .aRad += n .aRad * s
182
184
G .yx += n .yx * s
183
185
if n .derH : G .derH .add_tree (n .derH , root = G , rev = s == - 1 , fc = fc )
184
186
if fc :
185
- G .L += 1 # nodes doesn't have M and L? We just need to accumulate M and L into C
187
+ G .M += n . m * s ; G . L += s
186
188
else :
187
- if n .extH : G .extH .add_tree (n .extH , root = G , rev = s == - 1 )
188
- G .box = extend_box ( G .box , n .box )
189
-
190
- def combine_altG__ (root ): # combine contour G.altG_ into altG (node_ defined by root=G), for agg+ cross-comp
191
-
192
- for G in root .node_ : # eval altG * borrow from G:
193
- if isinstance (G .altG_ , list ) and G .altG_ : # skip converted alt or empty altG_
194
- altG_ = G .altG_ ; G .altG_ = CG (node_ = altG_ , root = G ); G .altG_ .sign = 1
195
- if val_ (np .sum ([alt .Et for alt in altG_ ],axis = 0 ), mEt = G .Et ):
196
- G .altG_ .L = len (G .altG_ .node_ )
189
+ if n .extH : G .extH .add_tree (n .extH , root = G , rev = s == - 1 ) # empty in centroid
190
+ G .box = extend_box ( G .box , n .box ) # extended per separate node_ in centroid
191
+
192
+ def comb_altG_ (root ): # combine contour G.altG_ into altG (node_ defined by root=G), for agg+ cross-comp
193
+
194
+ for G in root .node_ :
195
+ if G .nest + 1 == root .nest and G .altG_ :
196
+ alt_ = G .altG_
197
+ sum_G_ (alt_ [0 ], [alt for alt in alt_ [1 :]])
198
+ G .altG_ = CG (root = G , node_ = alt_ ); G .altG_ .sign = 1 ; G .altG_ .m = 0
199
+ # alt D * G rM:
200
+ if val_ (G .altG_ .Et , mEt = G .Et ):
197
201
cross_comp (G .altG_ )
198
- else :
199
- sum_G_ (G .altG_ , [alt for alt in G .altG_ ])
200
- # or keep altG_ in altG.node_?
201
202
202
203
if __name__ == "__main__" :
203
204
image_file = './images/raccoon_eye.jpeg'
@@ -208,7 +209,7 @@ def combine_altG__(root): # combine contour G.altG_ into altG (node_ defined by
208
209
if frame .node_ : # converted edges
209
210
G_ = []
210
211
for edge in frame .node_ :
211
- combine_altG__ (edge )
212
+ comb_altG_ (edge )
212
213
cluster_C_ (edge ) # no cluster_C_ in vect_edge
213
214
G_ += edge .node_ # unpack edge, or keep if connectivity cluster, or in flat blob altG_?
214
215
frame .node_ = G_
0 commit comments