arXiv:2610.41494cs.CVOct 2026

Manuscript Offprint

arXiv:2610.41494

VariaFlow: Uncertainty-Aware Flow Matching for Unsupervised Anomaly Detection

Arnela Hadzic, Martin Urschler, Cosmin I. Bercea

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Reconstruction-based anomaly detection no longer fails at reconstruction. Generative models produce high-quality pseudo-healthy reconstructions, and the remaining difficulty is the step of scoring residuals. The residual between a scan and its reconstruction has two indistinguishable sources, genuine pathology and the anatomical variation that separates one healthy brain from another. Scoring against a single reconstruction treats both as anomalous, inflating false positives where healthy anatomy varies most while small or subtle lesions are lost in the surrounding reconstruction error. We identify the missing quantity as the predictive variance, how much a healthy reconstruction can vary at each location. We introduce VariaFlow, which estimates this variance from an ensemble of mask-guided restorations under an unconditional flow matching prior, each started from a different noise initialization, and which normalizes the residual by the resulting standard deviation. Few-step flow matching keeps the ensemble computationally affordable, and restoring at two spatial scales captures lesions of different size. Across three brain MRI datasets spanning stroke and tumor, VariaFlow is trained once on healthy anatomy and generalizes across all three, attaining the highest AUROC (0.94, 0.80, 0.78) on each and the highest AUPRC on both cross-domain datasets, exceeding the strongest baseline by 37% and 50%. Under domain shift, the same baseline drops by up to 52% in AUPRC, whereas VariaFlow stays more stable and achieves the best small-lesion Dice on all three datasets.

1. Introduction

Brain anomaly detection localizes pathology in medical scans, such as tumors and stroke lesions. Supervised segmentation methods are effective [20, 22, 23, 40] but require

pixel-wise lesion annotations and segment only the pathologies they were trained on. Unsupervised methods instead learn the distribution of healthy anatomy and flag deviations from it, reconstructing an input as a pseudo-healthy image with a deep generative model and scoring the residual between the input and that reconstruction. Alternatively, feature-based methods detect anomalies by projecting images into a feature space via networks usually pre-trained on natural images [17, 36]. Recent advancements extend this by extracting representations directly from large foundation models [14, 18, 39]. However, the reliance on natural priors introduces a semantic gap, reducing their reliability in the medical domain. In contrast, reconstruction-based methods remain the dominant paradigm for brain MRI anomaly detection, as they yield intuitive pixel-level anomaly maps that are more suitable for segmentation tasks [7].

Among these reconstruction-based methods, autoencoders [33, 43, 44] learn the distribution of healthy anatomy but output blurry reconstructions, which misses small or subtle pathology and inflates residuals from normal anatomical variation [10]. While Generative Adversarial Networks (GANs) sharpen the reconstructions, they are unstable to train and prone to mode collapse [37, 38]. Diffusion models offer superior training stability and deliver high-fidelity reconstructions, but do so at a high cost of many iterative sampling steps [6, 12, 42]. Flow matching models have gained in prominence to address this computational cost by learning straighter generative trajectories [26, 27]. The REFLECT method has recently adapted flow matching to generate pseudo-healthy reconstructions of anomalous scans [8], but it does so in a compressed latent space which again leads to smoothing or even missing of subtle anatomical details or lesions.

We hypothesize that a flow matching prior for efficient reconstruction-based anomaly detection requires the uncompressed input representation, as provided by recent flow priors for image restoration and inpainting [19, 31].

Figure

Figure 1. Given an input image, VariaFlow generates an ensemble of pseudo-healthy reconstructions (x^(1),x^(2),…,x^(N)\hat{x}^{(1)}, \hat{x}^{(2)}, \ldots, \hat{x}^{(N)}). In anomalous regions, the model consistently generates healthy tissue, yielding a high residual (RR) and low predictive variance (σ2\sigma^2). Conversely, in variable healthy regions (e.g., ventricle boundaries), anatomical variability causes reconstructions to diverge, creating high predictive variance. Penalizing the residual with the variance suppresses false positives, isolating the pathology in the anomaly score map (SS).

Moreover, we argue that the standard practice of aforementioned reconstruction-based methods, i.e., to score residuals against a single reconstruction, is insufficient. Healthy reconstruction is an ill-posed inverse problem. Once pathology is removed, many healthy anatomies can map to the same observation because individuating structure, such as cortical folding, is underdetermined by the input. The conditional distribution over healthy reconstructions is therefore diffuse, and a point estimate, the conditional mean or a single sample, discards its spread. False positive detections therefore concentrate exactly where anatomy is most variable. Previous works have attempted to suppress false positives using restoration-based Maximum-A-Posteriori (MAP) estimation [15] or by modeling predictive uncertainty to calibrate anomaly scores [16, 30]. However, such uncertainty-aware methods typically rely on heavily modified training pipelines and explicitly force ensemble disagreement [16], assuming that ensembles will primarily disagree on anomalous regions. We argue that for high-fidelity generative models, this assumption is reversed: ambiguous healthy regions inherently exhibit high variance across an ensemble, whereas anomalous inputs are consistently mapped to similar pseudo-healthy reconstructions.

Based on these insights, we propose VariaFlow, an uncertainty-aware anomaly detector that generates an ensemble of mask-guided restorations with an efficient flow matching prior. While pathologies and healthy anatomical variations both deviate from a single reconstruction, only the latter falls within the variation expected across the ensemble. Penalizing the median residual with the per-pixel variance effectively suppresses false positives in healthy regions. We extract these components at both a coarse and

a fine masking scale, and fuse them via geometric mean before computing the final anomaly score, thus flagging a pixel only where both scales agree. We evaluate VariaFlow on multiple brain MRI datasets spanning two pathologies, stroke and tumor, and three acquisition sources, BraTS, UCSF, and ATLAS. Our main contributions are as follows:

  • We demonstrate that reconstruction-based anomaly detection greatly benefits from predictive variance, and show that scoring against a single reconstruction is what inflates false positives under anatomical variability.
  • We introduce the first flow-based reconstruction ensemble for brain anomaly detection, where few-step flow matching keeps variance estimation computationally tractable.
  • We propose a variance-penalized anomaly score and a dual-scale geometric mean fusion that together suppress false positives from normal variation while preserving anomalies of varying size.
  • Across stroke and tumor lesions and three datasets, VariaFlow improves detection and false positive suppression over diffusion- and flow-baselines, demonstrating superior robustness where the test cohort differs from training.

References (42)