SAM-Flow: Source-Anchored Masked Flow for Training-Free Image Editing

Haowang Cui, Rui Chen, Tao Luo, Tao Guo, Zheng Qin +1 more
6/4/2026
1 citation
cs.CV
diffusion-flow

Official code: chwbob/Sam-Flow (7 stars, Python, MIT, last commit 2026-06-13).

Abstract

Training-free image editing has recently attracted increasing attention due to its ability to modify real images using powerful pre-trained diffusion and flow-matching models without additional training. However, existing inversion-based and differential-flow-based methods usually perform global latent transport, which inevitably propagates editing effects to non-target regions and leads to background leakage.

Show full abstract

To address this problem, we propose SAM-Flow, a source-anchored masked flow framework for localized training-free image editing. Instead of updating the whole latent representation, SAM-Flow first uses a scout image and token-grounded attention maps to localize the editable semantic regions. It then applies differential velocity updates only within these regions, while anchoring the remaining areas to the source-image latent trajectory. To further improve spatial stability and boundary naturalness, we introduce a time-varying source-anchored projection mechanism with dynamic soft masks, transition regions, and temporal mask accumulation. The proposed method is plug-and-play and can be integrated with mainstream flow-matching backbones such as Stable Diffusion 3 and FLUX without any fine-tuning. Extensive qualitative and quantitative experiments demonstrate that SAM-Flow achieves accurate semantic editing while significantly improving background preservation, providing a simple and general localized editing paradigm for training-free image editing. Code is available at: https://github.com/chwbob/Sam-Flow.

View on arXivView PDF

Code Implementations(1)

chwbob/Sam-FlowOfficial100%
MIT

Official Pytorch implementation of the paper: "SAM-Flow: Source Anchored Masked Flow for Training-Free Image Editing"

71PythonJun 4, 20265 months agoMIT

Similar Papers

Cite this paper

@article{cui2026samflow,
  title  = {SAM-Flow: Source-Anchored Masked Flow for Training-Free Image Editing},
  author = {Haowang Cui and Rui Chen and Tao Luo and Tao Guo and Zheng Qin and Jiaze Wang},
  year   = {2026},
  eprint = {2606.06228},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2606.06228v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2606.06228.svg)](https://codeofpaper.com/paper/2606.06228)

Discussion