  Lack of standardization and various intrinsic parameters for magnetic
resonance (MR) image acquisition results in heterogeneous images across
different sites and devices, which adversely affects the generalization of deep
neural networks. To alleviate this issue, this work proposes a novel
unsupervised harmonization framework that leverages normalizing flows to align
MR images, thereby emulating the distribution of a source domain. The proposed
strategy comprises three key steps. Initially, a normalizing flow network is
trained to capture the distribution characteristics of the source domain. Then,
we train a shallow harmonizer network to reconstruct images from the source
domain via their augmented counterparts. Finally, during inference, the
harmonizer network is updated to ensure that the output images conform to the
learned source domain distribution, as modeled by the normalizing flow network.
Our approach, which is unsupervised, source-free, and task-agnostic is assessed
in the context of both adults and neonatal cross-domain brain MRI segmentation,
as well as neonatal brain age estimation, demonstrating its generalizability
across tasks and population demographics. The results underscore its superior
performance compared to existing methodologies. The code is available at
https://github.com/farzad-bz/Harmonizing-Flows
