Convolutional networks see the image through small windows. Each layer looks only at a few neighboring pixels, so a unit deep in the network gets information about distant regions only after many layers and downsampling steps, and that downsampling blurs object boundaries. The usual fixes have costs. Full attention compares every pixel with every other pixel, so cost grows with the square of the pixel count, and its weights leak across object edges. The cheaper axis-aligned or scan-order variants force information along rows, columns, or a one-dimensional reading order that has nothing to do with the image content. A third approach, the learnable tree filter, builds a minimum spanning tree over the pixel grid. This is the cheapest set of edges that connects all pixels, with edge cost equal to feature dissimilarity. The filter then passes messages along the tree in linear time. Its weakness is how it scores pairs: the affinity between two pixels is the product of edge affinities along their tree path. That product shrinks exponentially with path length, even inside a perfectly uniform region. The filter is therefore still mostly local, and its output jumps whenever a small change in edge weights alters which tree is chosen.
We propose replacing the path product with the quantity that the mathematical morphology literature identifies as the natural spanning-tree distance. This is the minimax or bottleneck distance: the largest single edge weight on the tree path between two pixels. Two pixels in the same uniform region are close no matter how far apart they are, and they become distant only when the path crosses a real boundary. Filtering with this distance can be computed exactly in linear time on the merge tree that Kruskal's algorithm produces. That merge tree is the hierarchy of watershed segmentations of the image, so the layer can be read as soft pooling over every level of a watershed hierarchy at once. Because the minimax distance does not depend on which minimum spanning tree is picked, the layer is continuous in its inputs and indifferent to how ties are broken. It also needs no random-tree trick to train.
Core Claim
Let $D(e) \ge 0$ be a learned dissimilarity on each edge $e$ of the 4-connected pixel graph. Let $d(u,v)$ be the minimax distance, the minimum over all graph paths from $u$ to $v$ of the largest $D(e)$ on the path. It equals the bottleneck edge on the unique path in any minimum spanning tree, as shown in the minimax path-connectivity work of Xiaolin Fan et al. and Shengfeng He et al.. We define the layer output for features $g$ as
$$ Y_u = \frac{\sum_{v} \phi\big(d(u,v)\big)\, g(v)}{\sum_{v} \phi\big(d(u,v)\big)}, $$
where $\phi$ is a learned positive decreasing function, for example $\phi(t) = e^{-t/\tau}$ with a learned per-channel temperature $\tau$.
The key computational fact is the following. Kruskal's algorithm merges components in increasing edge weight and so produces a binary merge tree, the dendrogram. In that tree, $d(u,v)$ equals the altitude $\lambda_a$ of the lowest common ancestor $a$ of $u$ and $v$. Grouping the sum by ancestors therefore gives a single root-to-leaf sweep. If $m(c)$ is the message reaching dendrogram node $c$, $p$ is the parent of $c$, and $s$ is the sibling of $c$ with feature sum $G(s)$, then
$$ m(c) = m(p) + \phi(\lambda_p)\, G(s), $$
and the pixel output is $m(\text{leaf}) + \phi(0)\,g(u)$. The subtree sums $G$ come from one leaf-to-root pass. Both passes are $O(N)$ once the dendrogram exists, and building the dendrogram costs one edge sort plus union-find.
Constructive Links between Some Morphological Hierarchies on Edge-Weighted Graphs shows that this dendrogram is the partition hierarchy of the minimum spanning tree and is isomorphic to the quasi-flat-zones hierarchy. Incremental Algorithm for Hierarchical Minimum Spanning Forests and Saliency of Watershed Cuts ties these hierarchies to watershed cuts. With exponential $\phi$, the layer also equals an exponentially weighted integral, over thresholds $t$, of mean-pooling inside the watershed region containing $u$ at level $t$. That identity is what makes the "pool over watershed regions" interpretation exact rather than loose.
The new claim is that this ultrametric filter does three things the learnable tree filter cannot. It carries signal across arbitrarily long homogeneous regions without decay. Its output is a continuous, almost-everywhere differentiable function of the edge dissimilarities, because the minimax distance is a min-of-max over paths and its gradient routes to the single bottleneck edge, much like max-pooling. And its output is invariant to MST tie-breaking, which closes both the plateau gap and the train/test mismatch noted for prior tree filters.
Relation to Prior Work
Two papers supply the starting point and the motivation. Learnable Tree Filter for Structure-preserving Feature Transform introduced linear-time two-pass filtering on a Borůvka minimum spanning tree with path-product affinities. It beat a non-local block on Cityscapes at a fraction of the cost, but it inherits exponential decay with path length. Rethinking Learnable Tree Filter for Generic Feature Transform patched the decay with a learnable per-node unary term and patched non-differentiable tree construction by sampling random spanning trees during training. It still uses a deterministic minimum spanning tree at test time, so it is trained on one distribution of trees and evaluated on another. We keep their linear-time, boundary-respecting spirit. We change the affinity itself, so that neither patch is needed and nothing differs between training and inference.
Real-Time Salient Object Detection with a Minimum Spanning Tree is the closest use of the minimax idea. It computes a barrier distance on the tree, but only from boundary seeds, using hand-crafted colors and no learning. We compute all-pairs minimax-weighted aggregation inside a trained network.
Three papers constrain the design. Differentiable Clustering with Perturbed Spanning Forests and Probabilistic Watershed make spanning forests differentiable through noise expectations and through Laplacian linear solves, respectively. The first is limited to batches of a few hundred points because it builds dense similarity matrices. The second needs a sparse solve per forward pass. Both are too heavy for dense feature maps with $10^5$ pixels, which is why we rely on the exact piecewise gradient of the minimax distance rather than on smoothing. Power watersheds shows that the minimum-spanning-forest limit of energy minimization has plateau ties that need extra machinery to resolve. Our layer avoids the problem because the minimax distance has no ties to break.
The competing context modules come from the receptive-field literature. CCNet uses axis-aligned criss-cross attention. Compact Generalized Non-local Network makes non-local attention linear through a Taylor approximation. EccoMamba uses scan-order state-space models, which need extra modules to undo directional bias. None of these follows image content when choosing its routes.
Research Program
We will build the layer as a drop-in context module with three parts. The first is a small convolutional head predicting $D(e)$ from low-level features, as in the learnable tree filter. The second is a GPU Borůvka minimum spanning tree followed by a Kruskal-order dendrogram construction on the tree's $N-1$ edges, which needs only sorting those edges and union-find. The third is two dendrogram sweeps implemented as level-synchronous scatter operations. The dendrogram can be deep on images with long monotone gradients, so we will also implement a pointer-jumping variant and report wall-clock time against CCNet and the learnable tree filter at $1024 \times 2048$.
On the analysis side, we will prove and then numerically verify four properties of the layer: tie-breaking invariance, continuity in $D$, the exact gradient with respect to each bottleneck altitude, and the threshold-integral identity.
A known risk is single-linkage chaining: one spuriously low edge between two objects merges them early in the hierarchy. Path products partly resist this. We will measure chaining directly. If it hurts, we will test one principled remedy that stays within the morphology toolbox. That remedy is to replace raw altitudes with the area- or volume-based attribute altitudes of the same hierarchy, which can be computed on the dendrogram in linear time. These suppress small leaky merges without breaking the linear-time sweep.
Baselines
The naive reference is the same backbone, a dilated ResNet-50 or ResNet-101 fully convolutional network, with no context module but with the same head and training schedule. Every gain is measured against this.
The strongest tree-based competitor is LTF-V2 from Rethinking Learnable Tree Filter for Generic Feature Transform. It addresses the same two flaws we target, decay and differentiability, but by different means, and it reports 82.1% mIoU on Cityscapes. LTF-V1 from Learnable Tree Filter for Structure-preserving Feature Transform reports 74.9% mIoU on Cityscapes with ResNet-50, against 74.2% for a non-local block, and 80.8% with a vanilla ResNet-101. The strongest non-tree competitor is CCNet, at 81.9% mIoU on the Cityscapes test set and 45.76% on ADE20K validation.
Published numbers come from differing schedules, and the file does not say which split LTF-V2's 82.1% uses. We will therefore re-run LTF-V1, LTF-V2, CCNet, and a non-local block ourselves. Every module goes at the same backbone stage, with the same crop size, iteration count, and augmentation, and with an equal hyperparameter search budget of the same number of runs per method. We will use the official code where available. Published numbers serve only as a sanity check that our reproductions are faithful.
Beating the baselines means two things in the matched setting. The first is a gain over LTF-V2 larger than the run-to-run standard deviation over three seeds. The second is a gain at no more than LTF-V1's added cost, which was 1.0G FLOPs on ResNet-50.
Two ablations isolate the key ingredient. The first keeps our exact minimum spanning tree and code path but swaps the minimax affinity for LTF's path-product affinity, so that only the scoring rule changes. The second replaces the continuous threshold integral with hard mean-pooling inside watershed regions at $K$ fixed learned thresholds, which is the discrete-superpixel version of the same idea.
Why not just…?
Why not just use LTF-V2, whose unary term already fixes decay? The unary term lets salient nodes shout louder, but every pair's weight still shrinks with tree-path length. LTF-V2 also needs random spanning trees in training and a different, deterministic tree at test time. This is a real threat on aggregate mIoU. We settle it two ways: the matched comparison above, and the long-range probe below, where LTF-V2 should still show attenuation within large homogeneous classes and our layer should not.
Why not just pool features inside watershed regions at a few thresholds? This is the cheapest version of our idea, and the threshold-integral identity says our layer is its continuous limit. If $K$ hard levels match the continuous version, the contribution reduces to "multi-level watershed superpixel pooling", and we will report that honestly. We expect the hard version to lose because its gradient with respect to thresholds and altitudes is zero almost everywhere. The superpixel experience reported in Real-Time Salient Object Detection with a Minimum Spanning Tree also shows that hard region boundaries cause permanent errors on thin structures. The $K$-level ablation, measured on thin classes such as poles and signs, decides this.
Why not just use criss-cross attention or a scan-order state-space model? Both are mature and fast, and CCNet's reported numbers are close to the tree filters'. Their routes are fixed, either along rows and columns or along a reading order, and EccoMamba itself needed extra axial-shift modules to undo that order. Our claim is not that they lack global reach, but that they mix across boundaries. The boundary-band evaluation below tests exactly that. If CCNet matches us inside boundary bands, the structural argument fails.
Why not just smooth the spanning tree with noise, as in perturbed spanning forests? Averaging over noisy forests on a $10^5$-pixel grid needs many minimum spanning tree computations per step, and the method was demonstrated only at moderate batch sizes. The minimax distance is already continuous, so smoothing buys nothing it lacks. We will include a perturbed variant with a few samples only as a cost comparison.
Proposed Experiments
The main benchmarks are Cityscapes and ADE20K semantic segmentation, with PASCAL VOC 2012 as a third check, all using the matched protocol above. To test applicability beyond street scenes, we add Synapse multi-organ CT, where EccoMamba reports 81.51% average Dice. We report mIoU or Dice, FLOPs, memory, and latency.
Four decisive checks go beyond aggregate scores. The long-range probe bins pixel pairs inside the same ground-truth segment by tree-path length and measures the gradient of $Y_u$ with respect to $g(v)$. Our layer should be flat across bins, and both LTF versions should decay. The boundary probe measures mIoU and leakage, meaning the attention mass that crosses ground-truth boundaries, within narrow bands around object edges, where non-local and criss-cross attention should leak more. The tie invariance test randomly permutes the order of equal-weight edges, and of near-equal weights after quantizing $D$. It reports output variance, which should be zero for our layer and nonzero for LTF, and measures the gap between LTF-V2's random-tree training and its deterministic-tree inference. The chaining diagnostic counts how often two distinct ground-truth objects merge below the median altitude, with and without area-based attribute altitudes.
The proposal fails if three things happen together: the product-affinity ablation on the identical tree matches our layer, the long-range probe shows no difference, and the $K$-level hard pooling ablation matches the continuous version.
References
- Effective and Efficient Steiner Maximum Path-Connected Subgraph Search in Large Social Internet of Things
- Real-Time Salient Object Detection with a Minimum Spanning Tree
- Constructive Links between Some Morphological Hierarchies on Edge-Weighted Graphs
- Incremental Algorithm for Hierarchical Minimum Spanning Forests and Saliency of Watershed Cuts
- Learnable Tree Filter for Structure-preserving Feature Transform
- Rethinking Learnable Tree Filter for Generic Feature Transform
- Differentiable Clustering with Perturbed Spanning Forests
- Probabilistic Watershed: Sampling all spanning forests for seeded segmentation and semi-supervised learning
- Power watersheds: A new image segmentation framework extending graph cuts, random walker and optimal spanning forest
- CCNet: Criss-Cross Attention for Semantic Segmentation
- Compact Generalized Non-local Network
- EccoMamba: Enhanced Cross-hierarchical Continuity Orthogonal Mamba for Medical Image Segmentation