itasc.tracking_ultrack.atoms¶
Atom extraction: residual-conditioned foreground split by contour ridges.
Stage ① of the atom-based candidate pipeline. Pure, deterministic functions
shared by the interactive preview and the full-stack atoms.tif writer.
Functions
|
Region-adjacency graph of a label image: labels sharing a 4-connected border. |
|
Atom RAG plus the mean ridge strength on each shared border. |
|
Alternative connected unions the backbone did not take, admitted most-ambiguous-first up to the per-frame overlap budget. |
|
Backbone watershed-style merge tree over the atom RAG (always built). |
|
All connected atom-subsets of size 1..max_atoms with total area ≤ max_area. |
|
Split |
|
Atom label stack for a (T, Y, X) foreground + contour pair. |
|
(atoms, territory, residual_foreground, residual_contour, ridge) stacks, each (T, Y, X). |
|
Stable SHA-1 of the params, used to detect stale atoms.tif in DB-Gen. |
|
Return |
|
Write the atom label stack with the params + fingerprint embedded in the TIFF ImageDescription, so DB-Gen (②) can read what produced it. |
Classes
|
The knobs that fully determine an atom segmentation. |
|
How branch admission used the per-frame overlap budget. |
- class itasc.tracking_ultrack.atoms.AtomParams(fg_window=51, fg_cutoff=0.002, fg_strength=1.0, contour_window=51, contour_floor=0.01, contour_strength=1.0, atom_min_area=100)[source]¶
Bases:
objectThe knobs that fully determine an atom segmentation.
- Parameters:
- itasc.tracking_ultrack.atoms.extract_atoms_frame(residual_contour, territory, contour_floor, atom_min_area)[source]¶
Split
territoryinto atoms along the cleaned contour ridge.ridgeis where the residual contour exceedscontour_floor(a noise cutoff). Cores (ridge-free territory) seed a watershed that floods the residual-contour elevation, so a broken faint ridge still meets at the crest. Atoms smaller thanatom_min_areaare merged into the neighbouring atom they share the longest border with (see_merge_small_atoms); an atom that touches no other label is kept as-is, so no territory pixel is ever blanked.Returns
(atoms, ridge):atomsis theint32label image;ridgeis the boolean wallresidual_contour > contour_floorreturned asuint8(Y, X)— the exact array the watershed carves out of territory, surfaced so it can be tuned against directly. Small-atom merging only relabels pixels, so it does not move the ridge.
- itasc.tracking_ultrack.atoms.extract_atoms_stack_with_maps(fg, contour, params)[source]¶
(atoms, territory, residual_foreground, residual_contour, ridge) stacks, each (T, Y, X).
ridgeis the per-frameresidual_contour > contour_floorwall returned byextract_atoms_frame, accumulated as auint8stack.
- itasc.tracking_ultrack.atoms.extract_atoms_stack(fg, contour, params)[source]¶
Atom label stack for a (T, Y, X) foreground + contour pair.
Per frame: residual the fg map and threshold it into territory, residual the contour map into the watershed elevation, then
extract_atoms_frame. Returns the atom labels only — the residual maps are internal.- Return type:
- Parameters:
fg (ndarray)
contour (ndarray)
params (AtomParams)
- itasc.tracking_ultrack.atoms.params_fingerprint(params)[source]¶
Stable SHA-1 of the params, used to detect stale atoms.tif in DB-Gen.
- Return type:
- Parameters:
params (AtomParams)
- itasc.tracking_ultrack.atoms.write_atoms_tif(path, atoms, params)[source]¶
Write the atom label stack with the params + fingerprint embedded in the TIFF ImageDescription, so DB-Gen (②) can read what produced it.
- Return type:
- Parameters:
atoms (ndarray)
params (AtomParams)
- itasc.tracking_ultrack.atoms.atom_adjacency(atoms)[source]¶
Region-adjacency graph of a label image: labels sharing a 4-connected border.
- itasc.tracking_ultrack.atoms.atom_adjacency_weighted(atoms, residual_contour)[source]¶
Atom RAG plus the mean ridge strength on each shared border.
Returns
(adj, weights)whereadjis the same region-adjacency graph asatom_adjacency(), andweightsmaps each(u, v)edge (u < v) to the meanresidual_contourvalue on the 4-connected wall separating the two atoms — the saliency of that wall. This is the per-edge ridge weight the merge tree merges across and the branch admission orders by.The wall value of a border pixel-pair
(p ∈ u, q ∈ v)is the mean of the residual-contour atpandq(the elevation the watershed floods to join them); the edge weight is the mean over all such pairs.
- itasc.tracking_ultrack.atoms.build_atom_merge_tree(adj, weights, areas, *, min_area, max_area, min_frontier)[source]¶
Backbone watershed-style merge tree over the atom RAG (always built).
A binary partition tree by altitude: atoms are leaves, and edges (walls) are consumed in ascending ridge weight — weakest wall first — each merge creating an internal node = the union of the two regions it joins. Per connected component the leaves are the atoms and the root is the maximal connected merge; every node is a candidate. Because the structure is a tree, any two nodes are nested or disjoint, so overlaps among backbone nodes are ancestor↔descendant only (linear, not quadratic).
This is the same shape of hierarchy ultrack builds at the pixel level (
hg.watershed_hierarchy_by_*+min_area/max_area/min_frontierpruning), but with atoms — the agreed stage-① primitive — as leaves, implemented here without a higra dependency on the candidate path.Pruning: singletons (atoms) are always kept; an internal node is kept only when
min_area ≤ area ≤ max_areaand the wall joining it to its sibling (its parent merge’s frontier) is≥ min_frontier— a sub-threshold wall is a non-salient split, collapsed into the parent. Returns the kept candidate members as frozensets, singletons first.
- class itasc.tracking_ultrack.atoms.BranchReport(admitted=0, skipped=0, budget_hit=False)[source]¶
Bases:
objectHow branch admission used the per-frame overlap budget.
- itasc.tracking_ultrack.atoms.branch_unions(adj, weights, areas, backbone, *, max_area, overlap_budget)[source]¶
Alternative connected unions the backbone did not take, admitted most-ambiguous-first up to the per-frame overlap budget.
Best-first growth over the atom RAG enumerates connected unions (area ≤
max_area) in ascending bottleneck wall weight — the strongest wall that must be crossed to form the union, i.e. how near-tied its weakest internal split is. A near-tie is a coin-flip the tree may have gotten wrong; a strong wall is a confident separation. Singletons and backbone nodes are skipped (they are already candidates) but still expanded.Budget: admitting a candidate over atoms
SaddsΣ_{a∈S} k_anew overlap pairs, wherek_ais how many already-kept candidates contain atoma(initialised from the backbone, so branch↔backbone overlaps are charged; the backbone↔backbone floor is free). A running total is kept and admission stops the moment the next candidate would crossoverlap_budget— most-ambiguous-first, no overshoot.overlap_budget→ 0 admits nothing (pure backbone);overlap_budget→ large exhausts the lattice.Returns
(admitted_members, report).
- itasc.tracking_ultrack.atoms.enum_connected_unions(adj, areas, max_atoms, max_area)[source]¶
All connected atom-subsets of size 1..max_atoms with total area ≤ max_area.
BFS growth with a global
seenset — each subset is reached exactly once, deduped by frozenset. This is the full lattice (theoverlap_budget→ large limit ofbuild_atom_merge_tree()+branch_unions()); it explodes on dense frames, so it is retained as the equivalence reference for tests, not the default candidate-generation path.