Going from 2D to 3D¶
We start with:
For each velocity channel, a set (python dictionary) of pre-processed masks. We call the container for these masks and their corners
nodes
.An overlap threshold.
We also reserve an empty dictionary to store the 3D
trees
built from thesenodes
.
We go through each velocity channel and its associated set of nodes
in order:
On the first velocity channel we go through all of the
nodes
and initialize a newtree
for eachnode
(there are no existingtree
as this moment).For all subsequent velocity channels we:
Go through all of the
nodes
, for eachnode
we try to match it to an existingtree
:
To match, we take the dictionary of existing, non-terminated
tree
, for eachtree
, we:
Compare the mask overlap between the current
node
and the lastnode
on thetree
(the “lastnode
” on thetree
has to be on the previous velocity channel). The comparison is a “two way” comparison - we first create a combined (bit-wise AND) overlap mask between the currentnode
and the lastnode
on thetree
we’re trying to match to, then compute the overlap fraction for both the (combined mask, currentnode
) pair and the (combined mask, lastnode
on thetree
) pair. If the overlap fraction for either pair is greater than our overlap threshold, we consider it to be a match and append the currentnode
onto thetree
.We do this for each existing
tree
, regardless if the currentnode
has already matched with atree
- this means that a givennode
can match to multipletree
.This also means that multiple
nodes
can match to a giventree
. If this does happen (we match the currentnode
to a giventree
that has already matched with anothernode
on the current velocity channel), instead of appending the currentnode
onto the giventree
, we merge the currentnode
with the othernode
on the current velocity channel that has also matched with the giventree
before doing the append. This is so that, on each velocity channel of thetree
, we have a “unified” mask.
If, after all of this, no match is found for the current
node
, we initialize a newtree
from thenode
.Delete all of the terminated trees of length 1 (trees that were initialized by an unmatched
node
but didn’t match with anynode
in the next immediate velocity channel). This is to minimize the running number oftree
we are actively trying to match newnodes
onto.