Manuscript Offprint
arXiv:2610.41494VariaFlow: Uncertainty-Aware Flow Matching for Unsupervised Anomaly Detection
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 1. Given an input image, VariaFlow generates an ensemble of pseudo-healthy reconstructions (). In anomalous regions, the model consistently generates healthy tissue, yielding a high residual () and low predictive variance (). 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 ().
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.
Recent approaches predominantly utilize denoising dif-fusion models (DDPMs) [12, 21]. Early diffusion methods relied on classifier guidance to translate diseased images to healthy ones [41], whereas recent unsupervised methods corrupt an input with noise and learn to reverse the process for a pseudo-healthy reconstruction. However, standard diffusion introduces a sensitivity-precision trade-off, where excessive noise destroys fine healthy tissue details, while insufficient noise lets the model reconstruct the anomaly. To address this, AnoDDPM [42] replaces standard Gaussian noise with Simplex noise, which resembles certain tumor appearances and improves degradation for those pathologies, although it misses anomalies where the noise structure differs from the training, e.g., structural anomalies such as fractures [11]. pDDPM [5] applies diffusion in a patch-wise manner. However, training on patches is sub-optimal to capture the global anatomical context. Building on these foundations, methods such as AutoDDPM [9] and THOR [11] introduced more sophisticated guidance to refine the restorations. AutoDDPM combines automatic masking, stitching, and inpainting tasks, whereas THOR utilizes intermediate masks to reintegrate healthy tissue information during the reverse process. Inspired by the sequential refinement of diffusion models, IterMask [24] employs spatial masking with high-frequency guidance, iteratively shrinking the mask toward the anomaly. However, extracting high-frequency edge maps discards low-frequency information, forcing the model to infer tissue intensities from its training distribution, thus reducing robustness.
More recently, flow matching [26, 27] has been introduced as an alternative generative model to learn optimal transport paths between noise and data distributions, enabling more efficient inference compared to standard diffusion models. Specifically for image restoration, flow matching-based reconstruction priors provide substantial benefits in computational efficiency [19] compared with state-of-the-art diffusion-based priors like RePaint [29]. To the best of our knowledge, REFLECT [8] is currently the only flow-based method for unsupervised brain anomaly detection. By simulating synthetic anomalies on healthy scans during training, it learns a direct correction trajectory within a compressed variational autoencoder (VAE) latent space. However, while achieving highly efficient inference, latent compression inherently smooths fine anatomical details, making the model prone to missing small lesions.
3. Method
We propose VariaFlow, an uncertainty-aware approach for unsupervised brain anomaly detection that leverages a generative flow matching prior trained on healthy anatomy. At inference, anomaly detection is formulated as a mask-guided image restoration task where the model projects the input image onto a healthy manifold. Specifically, VariaFlow generates an ensemble of pseudo-healthy reconstruc-
tions to yield both a median reconstruction and a predictive variance map. We combine these two components into an anomaly score map where the predictive variance acts as a pixel-wise penalty, effectively suppressing false positives in healthy variable regions (see Fig. 1). Furthermore, the reconstruction process is governed by a dual-scale masking strategy that enforces cross-scale structural agreement, allowing the model to robustly handle anomalies of diverse morphologies.
3.1. Ensemble Restoration with Flow Prior
Flow Matching. Flow matching [26, 27] defines a continuous-time generative process by learning a time-dependent vector field . This field maps a simple base distribution, such as standard Gaussian noise , to a more complex data distribution via an ordinary differential equation (ODE):
To approximate the target vector field , flow matching employs a simulation-free training objective:
A common and highly effective choice for the probability path is the linear interpolation between the initial noise and a target data sample , formulated as . Consequently, the target velocity simplifies to .
During inference, a data sample can be generated by numerically integrating the learned ODE. For instance, using a standard Euler integration scheme with a step size , the state evolves iteratively:
Pseudo-Healthy Reconstructions. Given a learned flow prior of healthy anatomy, we adopt a corrupt-and-restore paradigm to detect anomalies. We opt for spatial masking as our corruption mechanism, forcing the restoration to rely on the surrounding anatomical context when inpainting from the healthy data distribution. Specifically, we process the input image using a dual-scale sliding window strategy defined by a set of distinct spatial scales , which represent a localized window and a larger contextual window , respectively.
For each scale , we apply a binary mask to the tissue within each window and employ Restora-Flow [19] to restore the occluded regions. During each ODE integration step, the intermediate flow state is spatially fused with the known, unmasked regions of the input image, and a trajectory correction mechanism is applied to ensure alignment with the learned flow prior and the observed input [19]. Finally, we aggregate the overlapping patches using a Hann window [34], which ensures smooth transitions and yields a single pseudo-healthy reconstruction .
To construct an ensemble, we execute the sliding-window restoration process times per scale, using a distinct initial noise state for each individual run. This yields a scale-specific ensemble of independent reconstructions, denoted as . As a result, structurally homogeneous regions yield consistent reconstructions across the samples, while regions of inherent structural ambiguity elevate the model's predictive variance.
3.2. Variance-Aware Anomaly Scoring
Scale-Specific Residuals and Variance. Given an ensemble of pseudo-healthy reconstructions, we first compute the median reconstruction and derive the corresponding reconstruction residual
(1)$$
Subsequently, we quantify the model's predictive uncertainty at that scale by computing the pixel-wise variance across the reconstructions:
Geometric Dual-Scale Fusion. To aggregate information across localized and larger contextual windows, we apply geometric mean fusion to the residuals and the variance maps. For the residuals, this acts as a spatial intersection, preserving only deviations that are consistent across both scales:
While fusion using the arithmetic mean is also a valid option, we show in our ablation experiments that the proposed geometric mean fusion leads to slightly better suppression of false positives (see Section 5.4).
Variance-Penalized Scoring. Finally, we compute the anomaly score as a variance-penalized residual. By normalizing the reconstruction error by the ensemble standard deviation, we obtain
where acts as a regularization parameter. In this formulation, the denominator calibrates the score to distinguish healthy anatomical variations from pathology. In variable healthy regions, high ensemble variance attenuates the score, suppressing false positives. In contrast, anomalous
Table 1. Number of images per lesion size category and dataset.
| Dataset | Small | Medium | Large |
|---|---|---|---|
| ATLAS | 189 | 152 | 59 |
| UCSF-PDGM | 30 | 126 | 257 |
| BraTS | 26 | 78 | 217 |
| Total | 245 | 356 | 533 |
regions yield a high residual but low variance , as the prior outputs consistent pseudo-healthy reconstructions. As a result, the denominator remains small and the resulting anomaly score highlights pathological deviations.
4. Experimental Setup
Datasets. Our experimental setup utilizes four T1-weighted MRI datasets: IXI and ATLAS v2.0 [25] for training and in-domain evaluation, alongside UCSF-PDGM [13] and BraTS2020 [1, 2, 32] for cross-domain testing. Following [11], we extract one mid-axial slice per patient, normalize intensities to the 98th percentile, and pad and resize the images to a resolution. We train the model on healthy slices from ATLAS () and IXI (), utilizing 58 healthy IXI slices for validation. In-domain testing is performed on 438 pathological mid-axial ATLAS slices with stroke lesions. Additionally, we evaluate the model's cross-domain generalization on 495 UCSF-PDGM and 369 BraTS pathological mid-axial slices with gliomas. As in [11], we exclude 20 ATLAS mid-axial slices with prominent artifacts and any mid-axial slices with lesions smaller than 4 pixels from the evaluation. The remaining anomalies are stratified into small ( pixels), medium, and large ( pixels) lesions. Table 1 provides the corresponding image distribution per lesion size category and dataset.
Evaluation Metrics and Baselines. Following related work [8, 11, 24], we assess binary segmentation performance by first determining the optimal threshold based on the maximum Dice coefficient () across the range . We then apply this threshold to compute Sensitivity (Sens), Precision (Prec), and Dice scores for different lesion categories (Small, Medium, Large). Additionally, we evaluate continuous anomaly maps using threshold-agnostic metrics. We use AUROC to measure how well a model distinguishes anomalies from healthy anatomy, as well as AUPRC to reflect false positive rates independently of the predominant healthy background and to address shortcomings of AUROC in the presence of imbalanced datasets. Additionally, we measure false positive suppression capabilities using Precision at 50% Sensitivity (P@S.5) to quantify precision at a fixed 50% operating point. We compare Vari-
¹https://brain-development.org/ixi-dataset
4
Table 2. Quantitative results on the ATLAS, UCSF-PDGM, and BraTS datasets. VariaFlow is compared to several state-of-the-art diffusion-and flow-based baselines. Bold and underline indicate the best and the second-best score per metric, respectively. <table><tr><td colspan="9">ATLAS</td></tr><tr><td rowspan="2">Method</td><td rowspan="2">AUROC ↑</td><td rowspan="2">AUPRC ↑</td><td rowspan="2">P@S.5 (%) ↑</td><td colspan="4">[Dice] (%) ↑</td><td rowspan="2">Sens (%) ↑</td><td rowspan="2">Prec (%) ↑</td></tr><tr><td>Average</td><td>Small</td><td>Medium</td><td>Large</td></tr><tr><td>AutoDDPM [9]</td><td>0.7116</td><td>0.0878</td><td>7.30</td><td>13.86</td><td>3.25</td><td>15.29</td><td>25.87</td><td>27.02</td><td>9.32</td></tr><tr><td>THOR [11]</td><td>0.7139</td><td>0.1389</td><td>8.59</td><td>21.72</td><td>6.71</td><td>26.68</td><td>27.96</td><td>24.66</td><td>19.40</td></tr><tr><td>IterMask² [24]</td><td>0.8582</td><td>0.4965</td><td>48.40</td><td>50.07</td><td>7.79</td><td>44.52</td><td>59.86</td><td>45.00</td><td>56.43</td></tr><tr><td>REFLECT [8]</td><td>0.9378</td><td>0.5812</td><td>61.14</td><td>55.86</td><td>9.42</td><td>46.86</td><td>66.78</td><td>56.62</td><td>55.13</td></tr><tr><td>VariaFlow</td><td>0.9417</td><td>0.5262</td><td>57.19</td><td>54.86</td><td>18.88</td><td>51.76</td><td>65.05</td><td>58.94</td><td>51.31</td></tr><tr><td colspan="10">UCSF-PDGM</td></tr><tr><td rowspan="2">Method</td><td rowspan="2">AUROC ↑</td><td rowspan="2">AUPRC ↑</td><td rowspan="2">P@S.5 (%) ↑</td><td colspan="4">[Dice] (%) ↑</td><td rowspan="2">Sens (%) ↑</td><td rowspan="2">Prec (%) ↑</td></tr><tr><td>Average</td><td>Small</td><td>Medium</td><td>Large</td></tr><tr><td>AutoDDPM [9]</td><td>0.6566</td><td>0.2452</td><td>23.18</td><td>31.52</td><td>1.86</td><td>17.12</td><td>38.86</td><td>51.59</td><td>22.33</td></tr><tr><td>THOR [11]</td><td>0.6512</td><td>0.2229</td><td>22.13</td><td>30.54</td><td>2.10</td><td>16.31</td><td>36.54</td><td>44.44</td><td>23.27</td></tr><tr><td>IterMask² [24]</td><td>0.6159</td><td>0.2016</td><td>17.96</td><td>26.71</td><td>0.93</td><td>13.60</td><td>31.73</td><td>54.73</td><td>17.66</td></tr><tr><td>REFLECT [8]</td><td>0.7235</td><td>0.3079</td><td>27.48</td><td>35.18</td><td>0.74</td><td>16.10</td><td>41.95</td><td>50.72</td><td>26.93</td></tr><tr><td>VariaFlow</td><td>0.7952</td><td>0.4222</td><td>40.15</td><td>44.16</td><td>2.44</td><td>27.92</td><td>49.28</td><td>52.11</td><td>38.31</td></tr><tr><td colspan="10">BraTS</td></tr><tr><td rowspan="2">Method</td><td rowspan="2">AUROC ↑</td><td rowspan="2">AUPRC ↑</td><td rowspan="2">P@S.5 (%) ↑</td><td colspan="4">[Dice] (%) ↑</td><td rowspan="2">Sens (%) ↑</td><td rowspan="2">Prec (%) ↑</td></tr><tr><td>Average</td><td>Small</td><td>Medium</td><td>Large</td></tr><tr><td>AutoDDPM [9]</td><td>0.6108</td><td>0.2276</td><td>21.19</td><td>29.60</td><td>2.12</td><td>14.99</td><td>35.82</td><td>52.71</td><td>20.58</td></tr><tr><td>THOR [11]</td><td>0.6218</td><td>0.2198</td><td>21.38</td><td>29.65</td><td>1.97</td><td>14.27</td><td>35.23</td><td>48.33</td><td>21.38</td></tr><tr><td>IterMask² [24]</td><td>0.5821</td><td>0.1904</td><td>17.88</td><td>26.93</td><td>1.39</td><td>13.12</td><td>31.59</td><td>58.71</td><td>17.47</td></tr><tr><td>REFLECT [8]</td><td>0.6828</td><td>0.2779</td><td>24.97</td><td>33.16</td><td>0.64</td><td>14.95</td><td>38.80</td><td>55.66</td><td>23.62</td></tr><tr><td>VariaFlow</td><td>0.7800</td><td>0.4162</td><td>39.45</td><td>43.65</td><td>2.57</td><td>23.73</td><td>48.59</td><td>52.95</td><td>37.13</td></tr></table> aFlow to several recent state-of-the-art baselines, including diffusion-based AutoDDPM [9] with iterative resampling, THOR [11] utilizing implicit guidance, IterMask² [24] featuring iterative masking, and flow-based REFLECT [8], utilizing their official implementations. All compared methods were trained from scratch on the same datasets. Implementation Details. Our unconditional flow matching prior model [26] uses a U-Net [35] network architecture and was trained for 1500 epochs using the AdamW optimizer [28], a learning rate of $2 \times 10^{-5}$, and a batch size of 16. All images were normalized to $[-1, 1]$. At inference, a dual-scale sliding window with 50% overlap extracts 49 local windows at the $32 \times 32$ scale ($s_l = 32$), and 9 windows at the $64 \times 64$ scale ($s_g = 64$). Each window is independently inpainted using 8 ODE steps. Restored windows are aggregated per scale. The regularization factor $\gamma$ in Eq. (4) was empirically set to 0.025, as it yielded the highest AUPRC in our initial experiments. ## 5. Results Table 2 shows the quantitative results for VariaFlow against state-of-the-art baselines across the ATLAS, UCSF-PDGM, and BraTS datasets. VariaFlow achieves superior robustness and generalization, outperforming existing diffusion and flow-based methods on unseen domains while remaining highly competitive in-domain. Qualitative results in Fig. 2 visually validate these findings, while Fig. 3 and Fig. 4 analyze the impact of our dual-scale strategy and of the ensemble size, respectively. Table 3 demonstrates the effectiveness of predictive variance in suppressing false positives. Lastly, Fig. 5 illustrates two scenarios where our approach still faces challenges in anomaly detection. ### 5.1. Quantitative Results On the in-domain ATLAS dataset, VariaFlow achieves the new state-of-the-art AUROC score for anomaly detection and highly competitive AUPRC as well as Average [Dice] scores for false positive suppression and segmentation capability, respectively. While REFLECT achieves higher over-  Figure 2. Qualitative anomaly detection results on ATLAS, UCSF-PDGM, and BraTS. Rows 1-2 show the input images and ground truth masks. Rows 3-6 visualize the anomaly maps generated by the baseline methods, and Row 7 shows the maps generated by VariaFlow, demonstrating both superior detection and false positive suppression. all AUPRC and a marginally higher Average 「Dice」, its reliance on latent-space compression likely limits its ability to resolve fine details. Although detecting small-sized lesions remains inherently challenging for all unsupervised methods, VariaFlow is more robust at these scales. Specifically, VariaFlow doubles the performance of REFLECT on small anomalies (18.88% vs. 9.42% 「Dice」) and notably improves upon medium-sized anomalies (51.76% vs. 46.86%). This is consistent with REFLECT's design, where compressing the input into a VAE latent space before applying flow matching likely smooths over fine anatomical details and subtle lesions. Conversely, VariaFlow's spatially conditioned restoration avoids the information loss introduced by the latent-space strategy, thus better preserving the high-frequency anatomical details necessary for detecting subtle pathologies. In the more challenging cross-domain evaluations using UCSF-PDGM and BraTS, the diffusion-based baselines AutoDDPM and THOR show higher Average 「Dice」 scores than on ATLAS, likely due to the presence of more prominent tumors in these datasets that are easier to detect. While domain shift challenges all unsupervised methods, top-performing in-domain baselines IterMask² and REFLECT suffer a more severe performance drop in most metrics. For instance, REFLECT's Average 「Dice」 drops from 55.86% on ATLAS to 35.18% on UCSF-PDGM and from 0.9378 to 0.6828 AUROC on BraTS. IterMask² shows a similar trend, as its domain-specific high-frequency guidance seems to overfit to the training domain's intensities. In contrast, VariaFlow remains more stable when generalizing to both domains, achieving state-of-the-art results across nearly all metrics. Notably, on UCSF-PDGM VariaFlow improves AUROC by 9.9% over the next best baseline REFLECT and achieves a new state-of-the-art Average 「Dice」 of 44.16%. Moreover, on BraTS, VariaFlow improves 14.2% upon the second best method in AUROC and achieves an Average  Figure 3. Comparison of window sizes ($s_l = 32$, $s_g = 64$) and fusion strategies, with geometric mean consistently yielding the highest AUPRC. [Dice] of 43.65%, an increment of 10.49%, thus demonstrating the superior detection performance and robustness compared to baseline approaches. Beyond detection performance, our cross-domain generalization results on UCSF-PDGM and BraTS also demonstrate VariaFlow's major improvement in false positive suppression. For all three false positive related metrics (AUPRC, P@S.5, Prec), improvements upon the second best method REFLECT range between 37% and 58%. This underlines that our strategy of uncertainty-aware dual-scale flow-based reconstruction can achieve accurate anomaly detection without the trade-off of excessive false positives. ## 5.2. Qualitative Results Anomaly maps generated by diffusion-based methods AutoDDPM and THOR (see Fig. 2, Rows 3-4) show reasonable overall detection performance, however, at the price of generating a large number of false positive detections. IterMask² (Row 5) also visually demonstrates an improved detection and false positive suppression, however, it does so only in the in-domain scenario due to its domain-specific high frequency guidance. REFLECT (Row 6) provides better detection than the other baselines, but its latent-space compression likely limits the spatial precision of its anomaly maps, which further hinders the detection of small and subtle lesions. In the cross-domain setting, its maps additionally exhibit many false positives. In contrast, VariaFlow yields well-localized anomaly maps across lesion sizes, with the largest gains in false positive suppression <table><thead><tr><th>Scoring</th><th>AUROC ↑</th><th>AUPRC ↑</th><th>[Dice] (%) ↑</th></tr></thead><tbody><tr><td>Mean residual</td><td>0.8463</td><td>0.3935</td><td>43.11</td></tr><tr><td>Median residual</td><td>0.8571</td><td>0.4008</td><td>43.91</td></tr><tr><td>Proposed (S)</td><td>0.9417</td><td>0.5262</td><td>54.86</td></tr></tbody></table> Table 3. Comparison of different scoring formulations. Median residual alone as proposed in Eq. (3). Mean residual is a variant that uses the mean reconstruction instead in Eq. (1). Based on median residual, our proposed (S) additionally penalizes variance.  Figure 4. Impact of the ensemble size $N$ on detection performance. Metrics stabilize at $N = 5$.  Figure 5. Examples of diverse anatomical and structural deviations. Left: The model detects an enlarged ventricle, dominating the lesion attached to it. Right: The model misses a lesion resembling cortical folding while detecting a prominent imaging artifact. in the challenging cross-domain setting. The importance of predictive variance to derive the anomaly score is also demonstrated in Fig. 1 via additional ATLAS examples, showing improved false positive suppression. While VariaFlow achieves strong detection and false positive suppression, we have identified a few cases in our testing data where our approach still faces challenges. The left part of Fig. 5 illustrates a case with low performance in Dice score. VariaFlow flags an enlarged ventricle adjacent to the annotated infarct, reducing Dice against the ground truth. The enlargement is consistent with ex vacuo dilatation, the expansion of the ventricle into space left by infarcted tissue, and is a genuine downstream effect of the stroke. ATLAS annotates only the infarct core, so this secondary change is absent from the ground truth despite being clinically real. The change is also diagnostic. Chronic infarction destroys tissue and the ventricle expands into the resulting void, whereas a mass such as a tumor compresses and displaces it. The direction of ventricular deformation reflects the underlying process, volume loss versus mass effect, and bears directly on distinguishing chronic stroke from neoplasm. The right part of Fig. 5 shows a subtle lesion that closely resembles normal surrounding tissue, which likely explains the missed detection. VariaFlow additionally responds to an imaging artifact at the skull base, counted as a false positive, though this too is a true deviation from healthy anatomy. Table 4. Computational and architectural comparison between methods. <table border="1"><tr><td>Method</td><td>Backbone Architecture</td><td>Steps</td><td>Time (s)</td><td>VRAM (GB)</td><td>Params (M)</td></tr><tr><td>THOR [11]</td><td>DDPM U-Net</td><td>350</td><td>3.58</td><td>0.52</td><td>~ 19</td></tr><tr><td>REFLECT [8]</td><td>LDM U-Net + VAE</td><td>5</td><td>0.12</td><td>1.67</td><td>~ 246</td></tr><tr><td>VariaFlow (single patch)</td><td></td><td></td><td>0.32</td><td>0.40</td><td></td></tr><tr><td>VariaFlow (global scale, $N=1$)</td><td></td><td></td><td>0.64</td><td>0.82</td><td></td></tr><tr><td>VariaFlow (local scale, $N=1$)</td><td>Restora-Flow U-Net [19]</td><td>8</td><td>2.92</td><td>3.34</td><td>~ 62</td></tr><tr><td>VariaFlow (dual-scale, $N=1$)</td><td></td><td></td><td>3.56</td><td>3.34</td><td></td></tr></table> ### 5.3. Computational Aspects Table 4 provides a runtime analysis across diffusion-based THOR [11], flow-based REFLECT [8], and our method, measured on a single NVIDIA A100 GPU (40 GB). REFLECT is the fastest approach, requiring 0.12 s to generate a single reconstruction, as it operates within a heavily compressed latent space. While computationally efficient, REFLECT exhibits reduced preservation of high-frequency anatomical details and weaker cross-domain generalization in our experiments (Fig. 2 and Tab. 2). For pixel-space generation, THOR and VariaFlow have comparable wall-clock runtimes of approximately 3.5 s per reconstruction, despite relying on fundamentally different generation strategies. THOR utilizes a DDPM U-Net (~19M parameters) and requires 350 sequential reverse diffusion steps, whereas VariaFlow achieves this runtime by parallelizing restorations of 58 patches using a Restora-Flow U-Net (~62M parameters) and an efficient 8-step flow matching prior. Specifically, generating a single full-image reconstruction (dual-scale, $N=1$) with our method involves parallelizing 49 local-scale ($s_l=32, 2.92$s) and 9 global-scale ($s_g=64, 0.64$s) windows. Since Restora-Flow [19] processes a fixed-size full-resolution tensor and represents each target window only through its binary mask, the cost per window remains approximately constant at 0.32 s (8 ODE steps), regardless of the mask size. Parallelizing all 58 windows on the GPU compresses what would sequentially take over 18 s into just 3.56 s. Importantly, the dual-scale VariaFlow configuration with $N=1$ already outperforms THOR (Fig. 4 and Tab. 2) at a comparable runtime. Our main configuration uses an ensemble of $N=5$ independent reconstructions. Executed sequentially, this takes 17.8 s with a peak memory of 3.34 GB, while the subsequent fusion and scoring add only negligible overhead. ### 5.4. Ablations and Limitations Ablation of window scales. Fig. 3 illustrates that fusing dual-scale outputs consistently improves the overall performance compared to single-scale baselines, with the geometric mean from Eq. (3) slightly outperforming the fusion via the arithmetic mean. Because it requires strict spatial agree- ment across both scales, the geometric mean fusion penalizes single-scale noise, yielding the highest AUPRC scores. Sensitivity analysis of ensemble size. Using the dual-scale output fusion via the geometric mean, Fig. 4 demonstrates the impact of varying the number of reconstructions $N$ in the ensemble. At $N=1$, the framework relies on a single fused estimate ($\sigma=0$). Constructing a generative ensemble at $N=2$ notably improves detection performance, increasing Average [Dice] from approximately 40% to 54% and AUPRC from 0.35 to 0.51. While overall performance continues to improve only marginally with larger values of $N$, relying on only two reconstructions can introduce adverse effects, such as both randomly aligning on a similar anatomy and failing to suppress a false positive. Further, the detection of small lesions continues to benefit from a more robust variance estimate. All metrics stabilize at $N=5$, which we select as our optimal setup, since scaling to $N=10$ doubles the inference time for negligible gains. Effect of predictive variance. Table 3 shows the impact of predictive variance by comparing different scoring functions at a fixed ensemble size ($N=5$) on ATLAS. We evaluated the median residual ($R$) from Eq. (3) on its own as a scoring function, as well as a variant where the mean reconstruction is used instead of the median in Eq. (1). Experimentally, the median residual provides slightly improved detection performance, however, relying solely on the residual still fails to account for natural anatomical deviations. By penalizing the median residual with the predictive variance, our proposed score $S$ achieves a substantial increase in detection performance (AUROC, [Dice]), while at the same time increasing AUPRC by 31% from 0.4008 to 0.5262, thus successfully suppressing false positives in variable healthy regions. Limitations. To enable a controlled comparison with prior work, we evaluate on 2D mid-axial slices only and exclude lesions smaller than 4 pixels. While the ensemble-based scoring itself extends directly to 3D, the number of sliding windows grows cubically, so a volumetric extension might require more efficient sub-volume restoration. ### 6. Conclusion We have introduced VariaFlow, an uncertainty-aware framework for unsupervised brain anomaly detection. VariaFlow addresses the primary limitation of single-reconstruction methods, where healthy anatomical variability is frequently misidentified as pathology. By efficiently generating a flow matching-based ensemble, our method utilizes a variance-penalized anomaly score and a dual-scale strategy to effectively detect anomalies and suppress false positives across varying lesion sizes. Experimental results on in-domain and cross-domain data demonstrate that VariaFlow outperforms existing diffusion- and flow-based baselines, maintaining robust performance across multiple brain MRI datasets. ## Acknowledgements This research was funded in whole or in part by the Austrian Science Fund (FWF) 10.55776/PAT1748423. The computational results have been achieved using the Austrian Scientific Computing (ASC) infrastructure. ## References [1] Spyridon Bakas, Hamed Akbari, Aristeidis Sotiras, Michel Bilello, Martin Rozycki, Justin S Kirby, John B Freymann, Keyvan Farahani, and Christos Davatzikos. Advancing the cancer genome atlas glioma MRI collections with expert segmentation labels and radiomic features. Scientific Data, 4(1): 170117, 2017. 4 [2] Spyridon Bakas, Mauricio Reyes, Andras Jakab, Stefan Bauer, Markus Rempfler, Alessandro Crimi, Russell Takeshi Shinohara, Christoph Berger, Sung Min Ha, Martin Rozycki, et al. Identifying the best machine learning algorithms for brain tumor segmentation, progression assessment, and overall survival prediction in the BRATS challenge. arXiv preprint arXiv:1811.02629, 2018. 4 [3] Christoph Baur, Robert Graf, Benedikt Wiestler, Shadi Albarqouni, and Nassir Navab. SteGANomaly: Inhibiting CycleGAN Steganography for Unsupervised Anomaly Detection in Brain MRI. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 718–727, 2020. 2 [4] Christoph Baur, Stefan Denner, Benedikt Wiestler, Nassir Navab, and Shadi Albarqouni. Autoencoders for unsupervised anomaly segmentation in brain MR images: A comparative study. Medical Image Analysis, 69:101952, 2021. 2 [5] Finn Behrendt, Debayan Bhattacharya, Julia Krüger, Roland Opfer, and Alexander Schlaefer. Patched diffusion models for unsupervised anomaly detection in brain MRI. In Medical Imaging with Deep Learning, pages 1019–1032, 2024. 3 [6] Finn Behrendt, Debayan Bhattacharya, Robin Mieling, Lennart Maack, Julia Krüger, Roland Opfer, and Alexander Schlaefer. Leveraging the mahalanobis distance to enhance unsupervised brain MRI anomaly detection. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 394–404, 2024. 1 [7] Finn Behrendt, Debayan Bhattacharya, Lennart Maack, Julia Krüger, Roland Opfer, and Alexander Schlaefer. A review of deep learning-based Unsupervised Anomaly Detection in brain MRI. Medical Image Analysis, 112:104076, 2026. 1 [8] Farzad Beizaee, Sina Hajimiri, Ismail Ben Ayed, Gregory Lodygensky, Christian Desrosiers, and Jose Dolz. RE-FLECT: Rectified Flows for Efficient Brain Anomaly Correction Transport. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 456–466, 2025. 1, 3, 4, 5, 8 [9] Cosmin I. Bercea, Michael Neumayr, Daniel Rueckert, and Julia A Schnabel. Mask, Stitch, and Re-Sample: Enhancing Robustness and Generalizability in Anomaly Detection through Automatic Diffusion Models. In ICML 3rd Workshop on Interpretable Machine Learning in Healthcare (IMLH), 2023. 3, 5 [10] Cosmin I Bercea, Daniel Rueckert, and Julia A Schnabel. What Do AEs Learn? Challenging Common Assumptions in Unsupervised Anomaly Detection. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 304–314, 2023. 1 [11] Cosmin I Bercea, Benedikt Wiestler, Daniel Rueckert, and Julia A Schnabel. Diffusion models with implicit guidance for medical anomaly detection. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 211–220, 2024. 3, 4, 5, 8 [12] Cosmin I Bercea, Philippe C Cattin, Julia A Schnabel, and Julia Wolleb. Denoising Diffusion Models for Anomaly Localization in Medical Images. Machine Learning for Biomedical Imaging, 3:687–711, 2025. 1, 3 [13] Evan Calabrese, Javier E Villanueva-Meyer, Jeffrey D Rudie, Andreas M Rauschecker, Ujjwal Baid, Spyridon Bakas, Soonmee Cha, John T Mongan, and Christopher P Hess. The University of California San Francisco preoperative diffuse glioma MRI dataset. Radiology: Artificial Intelligence, 4(6): e220058, 2022. 4 [14] Mathilde Caron, Hugo Touvron, Ishan Misra, Hervé Jégou, Julien Mairal, Piotr Bojanowski, and Armand Joulin. Emerging properties in self-supervised vision transformers. In 2021 IEEE/CVF International Conference on Computer Vision (ICCV), pages 9630–9640, 2021. 1 [15] Xiaoran Chen, Suhang You, Kerem Can Tezcan, and Ender Konukoglu. Unsupervised lesion detection via image restoration with a normative prior. Medical Image Analysis, 64:101713, 2020. 2 [16] Yi Gu, Yi Lin, Kwang-Ting Cheng, and Hao Chen. Re-visiting deep ensemble uncertainty for enhanced medical anomaly detection. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 520–530, 2024. 2 [17] Jia Guo, Shuai Lu, Lize Jia, Weihang Zhang, and Huiqi Li. Encoder-decoder contrast for unsupervised anomaly detection in medical images. IEEE Transactions on Medical Imaging, 43(3):1102–1112, 2024. 1 [18] Jia Guo, Shuai Lu, Weihang Zhang, Fang Chen, Huiqi Li, and Hongen Liao. Dinomaly: The less is more philosophy in multi-class unsupervised anomaly detection. In 2025 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 20405–20415, 2025. 1 [19] Arnela Hadzic, Franz Thaler, Lea Bogensperger, Simon Johannes Joham, and Martin Urschler. Restora-Flow: Mask-Guided Image Restoration with Flow Matching. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), pages 4943–4952, 2026. 1, 3, 4, 8 [20] Mohammad Havaei, Axel Davy, David Warde-Farley, Antoine Biard, Aaron Courville, Yoshua Bengio, Chris Pal, Pierre-Marc Jodoin, and Hugo Larochelle. Brain tumor segmentation with deep neural networks. Medical Image Analysis, 35:18–31, 2017. 1 [21] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems (NeurIPS), 33:6840–6851, 2020. 3 [22] Fabian Isensee, Paul F Jäger, Peter M Full, Philipp Vollmuth, and Klaus H Maier-Hein. nnU-Net for brain tumor segmentation. In International Workshop on Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries, pages 118–132, 2020. 1 [23] Konstantinos Kamnitsas, Enzo Ferrante, Sarah Parisot, Christian Ledig, Aditya V Nori, Antonio Criminisi, Daniel Rueckert, and Ben Glocker. DeepMedic for brain tumor segmentation. In International Workshop on Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries, pages 138–149, 2016. 1 [24] Ziyun Liang, Xiaogqing Guo, J Alison Noble, and Konstantinos Kamnitsas. IterMask2: Iterative unsupervised anomaly segmentation via spatial and frequency masking for brain lesions in MRI. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 339–348, 2024. 3, 4, 5 [25] Sook-Lei Liew, Bethany P Lo, Miranda R Donnelly, Artemis Zavaliangos-Petropulu, Jessica N Jeong, Giuseppe Barisano, Alexandre Hutton, Julia P Simon, Julia M Juliano, Anisha Suri, et al. A large, curated, open-source stroke neuroimaging dataset to improve lesion segmentation algorithms. Scientific Data, 9(1):320, 2022. 4 [26] Yaron Lipman, Ricky TQ Chen, Heli Ben-Hamu, Maximilian Nickel, and Matt Le. Flow matching for generative modeling. In International Conference on Learning Representations (ICLR), 2023. 1, 3, 5 [27] Xingchao Liu, Chengyue Gong, and Qiang Liu. Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow. In International Conference on Learning Representations (ICLR), 2023. 1, 3 [28] Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. In International Conference on Learning Representations (ICLR), 2019. 5 [29] Andreas Lugmayr, Martin Danelljan, Andres Romero, Fisher Yu, Radu Timofte, and Luc Van Gool. RePaint: Inpainting using denoising diffusion probabilistic models. In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 11461–11471, 2022. 3 [30] Wei Luo, Peng Xing, Yunkang Cao, Haiming Yao, Weiming Shen, and Zechao Li. URA-Net: Uncertainty-integrated anomaly perception and restoration attention network for unsupervised anomaly detection. IEEE Transactions on Circuits and Systems for Video Technology, 2025. 2 [31] Ségolène Martin, Anne Gagneux, Paul Hagemann, and Gabriele Steidl. Pnp-flow: Plug-and-play image restoration with flow matching. In International Conference on Learning Representations (ICLR), pages 45466–45492, 2025. 1 [32] Bjoern H Menze, Andras Jakab, Stefan Bauer, Jayashree Kalpathy-Cramer, Keyvan Farahani, Justin Kirby, Yuliya Burren, Nicole Porz, Johannes Slotboom, Roland Wiest, et al. The multimodal brain tumor image segmentation benchmark (BRATS). IEEE Transactions on Medical Imaging, 34(10):1993–2024, 2015. 4 [33] Nick Pawlowski, Matthew CH Lee, Martin Rajchl, Steven McDonagh, Enzo Ferrante, Konstantinos Kamnitsas, Sam Cooke, Susan Stevenson, Aneesh Khetani, Tom Newman, et al. Unsupervised Lesion Detection in Brain CT using Bayesian Convolutional Autoencoders. In Medical Imaging with Deep Learning, 2018. 1, 2 [34] Nicolas Pielawski and Carolina Wählby. Introducing Hann windows for reducing edge-effects in patch-based image segmentation. PloS one, 15(3):e0229839, 2020. 4 [35] Olaf Ronneberger, Philipp Fischer, and Thomas Brox. U-Net: Convolutional networks for biomedical image segmentation. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 234–241, 2015. 5 [36] Karsten Roth, Latha Pemula, Joaquin Zepeda, Bernhard Schölkopf, Thomas Brox, and Peter Gehler. Towards total recall in industrial anomaly detection. In 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 14298–14308, 2022. 1 [37] Thomas Schlegl, Philipp Seeböck, Sebastian M. Waldstein, Ursula Schmidt-Erfurth, and Georg Langs. Unsupervised Anomaly Detection with Generative Adversarial Networks to Guide Marker Discovery. In Information Processing in Medical Imaging, pages 146–157, 2017. 1, 2 [38] Thomas Schlegl, Philipp Seeböck, Sebastian M Waldstein, Georg Langs, and Ursula Schmidt-Erfurth. f-AnoGAN: Fast unsupervised anomaly detection with generative adversarial networks. Medical Image Analysis, 54:30–44, 2019. 1, 2 [39] Nico Schulthess and Ender Konukoglu. Anomaly Detection by Clustering DINO Embeddings using a Dirichlet Process Mixture. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 46–56, 2025. 1 [40] Ashish Sinha and Jose Dolz. Multi-scale self-guided attention for medical image segmentation. IEEE Journal of Biomedical and Health Informatics, 25(1):121–130, 2021. 1 [41] Julia Wolleb, Florentin Bieder, Robin Sandkühler, and Philippe C Cattin. Diffusion models for medical anomaly detection. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 35–45, 2022. 3 [42] Julian Wyatt, Adam Leach, Sebastian M Schmon, and Chris G Willcocks. AnoDDPM: Anomaly detection with de-noising diffusion probabilistic models using simplex noise. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops, pages 650–656, 2022. 1, 3 [43] David Zimmerer, Fabian Isensee, Jens Petersen, Simon Kohl, and Klaus Maier-Hein. Unsupervised anomaly localization using variational auto-encoders. In International Conference on Medical Image Computing and Computer-Assisted Intervention (MICCAI), pages 289–297, 2019. 1, 2 [44] David Zimmerer, Simon AA Kohl, Jens Petersen, Fabian Isensee, and Klaus H Maier-Hein. Context-encoding Variational Autoencoder for Unsupervised Anomaly Detection. In Medical Imaging with Deep Learning, 2019. 1, 2