diff --git a/frame_2D_alg/frame_blobs.py b/frame_2D_alg/frame_blobs.py index 7f7ee5edb..12b0eba3e 100644 --- a/frame_2D_alg/frame_blobs.py +++ b/frame_2D_alg/frame_blobs.py @@ -50,7 +50,6 @@ UNFILLED = -1 EXCLUDED = -2 - class Cder__t(NamedTuple): dy: Any dx: Any @@ -59,13 +58,11 @@ class Cder__t(NamedTuple): def get_pixel(self, y: Real, x: Real) -> Tuple[Real, Real, Real]: return self.dy[y, x], self.dx[y, x], self.g[y, x] - class Cbox(NamedTuple): n: Real w: Real s: Real e: Real - # properties @property def cy(self) -> Real: return (self.n + self.s) / 2 @@ -73,12 +70,10 @@ def cy(self) -> Real: return (self.n + self.s) / 2 def cx(self) -> Real: return (self.w + self.e) / 2 @property def slice(self) -> Tuple[slice, slice]: return slice(self.n, self.s), slice(self.w, self.e) - # operators: def __add__(self, other: Cbox) -> Cbox: """Add 2 boxes.""" return Cbox(min(self.n, other.n), min(self.w, other.w), max(self.s, other.s), max(self.e, other.e)) - # methods def accumulate(self, y: Real, x: Real) -> Cbox: """Box coordinate accumulation.""" diff --git a/frame_2D_alg/vectorize_edge_blob/classes.py b/frame_2D_alg/vectorize_edge_blob/classes.py index b399c6650..2891f938e 100644 --- a/frame_2D_alg/vectorize_edge_blob/classes.py +++ b/frame_2D_alg/vectorize_edge_blob/classes.py @@ -14,7 +14,7 @@ prefix 'C' denotes class postfix 't' denotes tuple, multiple ts is a nested tuple postfix '_' denotes array name, vs. same-name elements - prefix '_' denotes prior of two same-name variables + prefix '_' denotes prior or not-self of two same-name variables prefix 'f' denotes flag 1-3 letter names are normally scalars, except for P and similar classes, capitalized variables are normally summed small-case variables, @@ -102,6 +102,36 @@ def comp(self, other: Cdertuple, rn: Real) -> Tuple[Cmd, Cmd, Cmd]: # comp_de return ddertuplet, valt, rdnt +class CP(CBase): # horizontal blob slice P, with vertical derivatives per param if derP, always positive + + ptuple: Cptuple = z(Cptuple()) # latuple: I,G,M,Ma, angle(Dy,Dx), L + rnpar_H: list = z([]) + derH: CderH = z(CderH()) # [(mtuple, ptuple)...] vertical derivatives summed from P links + valt: Cmd = z(Cmd(0, 0)) # summed from the whole derH + rdnt: Cmd = z(Cmd(1, 1)) + dert_: list = z([]) # array of pixel-level derts, ~ node_ + cells: set = z(set()) # pixel-level kernels adjacent to P axis, combined into corresponding derts projected on P axis. + roott: list = z([None,None]) # PPrm,PPrd that contain this P, single-layer + axis: Cangle = Cangle(0, 1) # prior slice angle, init sin=0,cos=1 + yx: tuple = None + ''' + link_H: list = z([[]]) # all links per comp layer, rng+ or der+ + dxdert_: list = z([]) # only in Pd + Pd_: list = z([]) # only in Pm + Mdx: int = 0 # if comp_dx + Ddx: int = 0 + ''' + + # it's conditional in comp_rng, and we need to pass A,S, so it should be in comp_slice? + def comp(self, other: CP, link_: List[CderP], rn: Real, S: Real = None): + + dertuplet, valt, rdnt = self.ptuple.comp(other.ptuple, rn=rn) + + if valt.m > ave_Pm * rdnt.m or valt.d > ave_Pm * rdnt.d: + derH = CderH([dertuplet]) + link_ += [CderP(derH=derH, valt=valt, rdnt=rdnt, _P=self, P=other, S=S)] + + class CderH(list): # derH is a list of der layers or sub-layers, each = ptuple_tv __slots__ = [] @@ -143,35 +173,6 @@ def comp(self, other: CderH, rn: Real, n: Real = inf) -> Tuple[CderH, Cmd, Cmd]: return dderH, valt, rdnt # new derLayer,= 1/2 combined derH -class CP(CBase): # horizontal blob slice P, with vertical derivatives per param if derP, always positive - - ptuple: Cptuple = z(Cptuple()) # latuple: I,G,M,Ma, angle(Dy,Dx), L - rnpar_H: list = z([]) - derH: CderH = z(CderH()) # [(mtuple, ptuple)...] vertical derivatives summed from P links - valt: Cmd = z(Cmd(0, 0)) # summed from the whole derH - rdnt: Cmd = z(Cmd(1, 1)) - dert_: list = z([]) # array of pixel-level derts, ~ node_ - cells: set = z(set()) # pixel-level kernels adjacent to P axis, combined into corresponding derts projected on P axis. - roott: list = z([None,None]) # PPrm,PPrd that contain this P, single-layer - axis: Cangle = Cangle(0, 1) # prior slice angle, init sin=0,cos=1 - yx: tuple = None - ''' - add L,S,A from links? - optional: - link_H: list = z([[]]) # all links per comp layer, rng+ or der+ - dxdert_: list = z([]) # only in Pd - Pd_: list = z([]) # only in Pm - Mdx: int = 0 # if comp_dx - Ddx: int = 0 - ''' - - def comp(self, other: CP, link_: List[CderP], rn: Real, S: Real = None): - dertuplet, valt, rdnt = self.ptuple.comp(other.ptuple, rn=rn) - if valt.m > ave_Pm * rdnt.m or valt.d > ave_Pm * rdnt.d: - derH = CderH([dertuplet]) - link_ += [CderP(derH=derH, valt=valt, rdnt=rdnt, _P=self, P=other, S=S)] - - class CderP(CBase): # tuple of derivatives in P link: binary tree with latuple root and vertuple forks _P: CP # higher comparand @@ -186,10 +187,10 @@ class CderP(CBase): # tuple of derivatives in P link: binary tree with latuple def comp(self, link_: List[CderP], rn: Real): dderH, valt, rdnt = self._P.derH.comp(self.P.derH, rn=rn, n=len(self.derH)) + if valt.m > ave_Pd * rdnt.m or valt.d > ave_Pd * rdnt.d: self.derH |= dderH; self.valt = valt; self.rdmt = rdnt # update derP not form new one link_ += [self] - ''' max n of tuples per der layer = summed n of tuples in all lower layers: 1, 1, 2, 4, 8..: lay1: par # derH per param in vertuple, layer is derivatives of all lower layers: @@ -198,9 +199,11 @@ def comp(self, link_: List[CderP], rn: Real): lay4: [[m,d], [md,dd], [[md1,dd1],[mdd,ddd]]]: 3 sLays, <=2 ssLays ''' - -class Cgraph(CBase): # params of single-fork node_ cluster per pplayers - +class Cgraph(CBase): # params of single-fork node_ cluster + ''' + We may need nested ext: top level summed from link_, lower levels from nodes, per level of node_ hierarchy. + That's parallel to aggH( subH, so we should have ext packed in each subLay and aggLev, same as in derH? + ''' fd: int = 0 # fork if flat layers? ptuple: Cptuple = z(Cptuple()) # default P derH: CderH = z(CderH()) # from PP, not derHv diff --git a/frame_2D_alg/vectorize_edge_blob/comp_slice.py b/frame_2D_alg/vectorize_edge_blob/comp_slice.py index a21c7c063..946d289d0 100644 --- a/frame_2D_alg/vectorize_edge_blob/comp_slice.py +++ b/frame_2D_alg/vectorize_edge_blob/comp_slice.py @@ -113,14 +113,16 @@ def sum2PP(root, P_, derP_, base_rdn, fd): # sum links in Ps and Ps in PP P.derH += derH; P.valt += valt; P.rdnt += rdnt + (base_rdn, base_rdn) # P.derH sums link derH s _P = derP._P # bilateral accum downlink, reverse d signs: _P.derH -= derH; _P.valt += valt; _P.rdnt += rdnt + (base_rdn, base_rdn) + PP.A += derP.A + PP.S += derP.S PP.link_ += [derP] celly_,cellx_ = [],[] for P in P_: # accum Ps: PP.ptuple += P.ptuple # accum ptuple - for y, x in P.cells: - PP.box = PP.box.accumulate(y, x) + for y,x in P.cells: + PP.box = PP.box.accumulate(y,x) celly_ += [y]; cellx_ += [x] # unilateral sum: PP.derH += P.derH