LensErase: A Foundation Model for Erase Anything
Yunuo Chen, Xiuyu Wu, Qinhong Yang, Jinjing Zhao, Yanchen Dong, Sirui Zhang, Dong Chen, Fangyun Wei, Lei Shi, Ji Li, Dongdong Chen, Guo Lu, Yan Lu, Baining Guo
LensErase is a foundation model for object removal that uses large-scale synthetic data and reinforcement learning to handle diverse erase scenarios.
How can we build a single foundation model capable of removing diverse visual elements—objects, text, and watermarks—while maintaining high-fidelity background consistency?
General-purpose object removal models often struggle to handle the diverse requirements of real-world editing, such as removing translucent watermarks, visual text, or large objects while preserving surrounding scene consistency. The authors introduce LensErase, which adapts a pretrained text-to-image model to mask-based erasing using a 101-million-pair synthetic dataset and a 3D rotary positional encoding that injects mask information directly into image tokens. On both public benchmarks and the authors' new 500-case evaluation set, LensErase consistently outperforms existing methods in removal completeness, reconstruction quality, and content preservation.
Paper Primer
The core challenge in object removal is the "entanglement" of the target with its environment: removing a foreground object often leaves behind shadows, reflections, or artifacts, while erasing text requires surgical precision to avoid damaging the underlying carrier. LensErase addresses this by treating the source image and mask as a unified visual input, leveraging a pretrained generative prior to reconstruct missing regions.
The method hinges on Mask-Aware RoPE: a 3D rotary positional encoding that maps the mask directly into the source-image tokens. This allows the model to identify the target and its associated effects without needing a separate mask-token sequence, effectively turning the erasure task into a conditional image-to-image generation problem.
LensErase achieves superior removal and reconstruction quality across diverse benchmarks.
In the LensErase-Bench evaluation, the model achieved an overall score of 95.22 compared to the next best baseline (OmniPaint) at 73.59. The model reached an 82.8% High-Fidelity Removal rate, significantly higher than the 42.8% achieved by the strongest competing baseline.
To ensure reliability, the authors refine the model using reinforcement learning with "contract-guided" rewards. This process uses a GPT-based judge to evaluate candidates against a specific "erase contract" that explicitly defines what must be removed (targets and effects) and what must be preserved (independent background objects).
Why is a new 101-million-pair dataset necessary for this task?
Existing object-removal datasets are typically two to three orders of magnitude smaller (100K–1M examples). The authors' large-scale dataset is required to cover the specific, diverse challenges of real-world erasing, including translucent watermarks, visual text, and large-scale object removal, which are under-represented in smaller, general-purpose datasets.
What is the role of TraceFusion at inference time?
TraceFusion acts as a post-processing step that estimates the "effective edit region" by comparing the source and output images. It selectively restores the original source image in areas where the model might have introduced unintended changes, ensuring high-fidelity preservation of the background.
The model's reliance on synthetic data construction—specifically the use of GPT-4 to generate insertion instructions and SAM2 to create masks—is the primary engine for its scale. The authors assume that a model trained on these diverse, synthetically generated "erase" pairs will generalize to real-world, user-provided images.
LensErase demonstrates that large-scale synthetic data and reinforcement learning can transform general-purpose generative priors into highly reliable, specialized tools for complex image editing.
Introduction to LensErase
LensErase unifies diverse erasure tasks in a single foundation model.
Object erasing underlies many visual‑production pipelines, from photography retouching to automated graphic design. An ideal erase model must infer the user’s intent, remove all visual evidence of the target, and plausibly reconstruct the missing region while leaving the rest of the image untouched.
In practice, targets appear at wildly different spatial scales, from tiny logos (< 1 % of the image) to dominant foreground objects (≈ 50 %). Moreover, erasing text, watermarks, or reflections introduces distinct reconstruction challenges, and multi‑object removal must preserve global scene consistency despite spatially separated edits.
Build a single “Erase Anything” foundation model that can handle objects, visual text, watermarks, associated effects, and multi‑object edits across arbitrary scales and resolutions, using only an image and a mask as condition.
**Figure 1** LensErase across diverse removal scenarios. Each pair shows a source image with highlighted removal targets and the corresponding LensErase result. Examples cover general objects, visual text, watermarks, multiple objects, coupled effects, and high-fidelity inpainting.
LensErase provides a unified foundation model for all erase‑related tasks, simplifying pipelines and enabling consistent high‑quality results across diverse scenarios.
Training Data and Pipeline
We assemble a 100 M‑scale triplet dataset covering diverse erasure tasks.
Training a universal eraser requires massive, diverse supervision. Existing datasets are either too small or focus on a single erasure type, leading to models that over‑fit to narrow tasks and fail on real‑world variations.
Each category follows a bespoke pipeline that turns raw images into (Iinput, Ioutput, M) triplets, guaranteeing that the mask precisely isolates the erased region while the target image remains a clean reference.
General Data: we first sample three coarse object categories, ask GPT‑4.1 to pick an absent object and generate an insertion instruction, synthesize the inserted image with a pretrained editor Gadd, then derive a high‑recall change mask via DCT/DINOv3 differences and refine it with SAM2 prompts.
Watermark Data: a watermark asset is randomly chosen, rendered onto a clean image with varied font, color, geometry, and opacity, and the resulting watermarked image, the original clean image, and the rendered region form the triplet.
Large‑Mask Data: a foreground object is generated on a white canvas, extracted with BiRefNet, then copy‑pasted onto a background image after YOLOE detects existing objects, ensuring the pasted object occupies a large, non‑overlapping region.
Visual Text Data: PaddleOCR detects text regions, an editor erases them while preserving carriers, OCR is run again to confirm removal, and Poisson blending merges the edited regions back into the original image to avoid seams.
Poster Data: a layout template is sampled, 4–9 elements with random styles are placed in explicit z‑order layers, the full poster is rendered, then a random subset of elements is deleted while keeping the background and remaining layers unchanged.
SFT Data: the same pipelines are reused on high‑resolution images, filtered by GPT‑5.6 Sol for mask validity and edit quality; Large‑Mask samples are omitted, while Poster examples are sourced from professional designers.
RL Data: 19 K tasks are curated from disjoint images, emphasizing hard/extreme General cases and balanced contributions from Poster, Watermark, and Visual Text; the model receives only Iinput and M, with deterministic clean references for Poster and Watermark.
LensErase‑Bench evaluates 500 curated removal cases without paired references, using a VLM judge to score Removal, Inpainting, Preservation, and Cleanliness on a 0–4 scale, then aggregates them into a weighted overall score and a High‑Fidelity Removal Rate.
**Figure 2** Left: Distribution of mask area ratios. Right: Distribution of mask counts.
**Figure 4** Data composition across training stages. Dataset sizes and category counts for pretraining, SFT, and RL. Bands connect shared categories across stages.
LensErase‑100M provides a 100 M‑scale, five‑category foundation that fuels both supervised fine‑tuning and reinforcement learning, enabling a single model to master object, watermark, large‑mask, visual‑text, and poster erasure.
The LensErase Architecture
Method details the two‑branch MMDiT design, mask‑aware RoPE, and region‑weighted training.
Erasing objects while preserving surrounding context requires the model to know exactly where the mask lies and to keep useful visual cues from the masked region.
The model runs two parallel transformer branches—one for the noisy target latent and one for the source latent—then merges them in a joint self‑attention block, much like two chefs preparing separate ingredients before combining them in a shared pot.
How does this two‑branch design differ from the single‑branch transformer used in standard text‑to‑image models?
In a standard model the condition input is a text embedding, so a single branch suffices. Here the condition is a visual tensor (source latent plus mask), so a separate branch processes it in its own token space before the two streams are fused.
Mask‑Aware RoPE extends the usual 2‑D rotary positional embedding with an extra modality dimension that directly encodes whether a token comes from a masked or unmasked region, similar to adding a third colour channel that flags masked pixels.
Top‑left token gets $p^{\text{cond}} = (1,0,0)$ (masked).
Top‑right token gets $p^{\text{cond}} = (0,0,1)$ (unmasked).
Bottom‑left token gets $p^{\text{cond}} = (0,1,0)$ (unmasked).
Bottom‑right token gets $p^{\text{cond}} = (1,1,1)$ (masked).
RoPE rotates each token’s embedding using its three‑component coordinate, producing distinct phase patterns for masked vs. unmasked tokens.
Because the mask value participates in the rotation, masked tokens acquire a representation that the attention mechanism can recognise and treat differently without extra mask embeddings.
How is Mask‑Aware RoPE different from the standard RoPE used for pure spatial encoding?
Standard RoPE only rotates based on the 2‑D spatial coordinates $(h,w)$. Mask‑Aware RoPE adds a third component $m_i$ (or the constant 2 for target tokens), so the rotation also depends on mask status, creating separate positional phases for masked and unmasked tokens.
Compute weights: $\omega = [1+4\cdot1,\,1+4\cdot0,\,1+4\cdot0,\,1+4\cdot1] = [5,1,1,5]$.
Assume predicted velocities $v_{\theta} = [0.2,0.1,0.1,0.3]$ and target velocities $\mathbf{v}^\star = [0,0,0,0]$.
Loss contribution per token: $5\cdot0.2^2 = 0.2$, $1\cdot0.1^2 = 0.01$, $1\cdot0.1^2 = 0.01$, $5\cdot0.3^2 = 0.45$.
Total $\mathcal{L}_{\text{FM}} = 0.2 + 0.01 + 0.01 + 0.45 = 0.67$.
The mask‑weighted loss concentrates the training signal on the masked tokens, making the model learn to edit precisely where needed.
The RL stage builds a deterministic “erase contract” that lists what must disappear (targets $T$ and effects $E$) and what must stay (protected objects $O$), then rewards policies that satisfy this contract.
Compute $n_0 = 2$ (two zero‑valued removal sub‑criteria).
Assume equal weights $\lambda_p = 0.2$ for all five components; base reward $b = 0.2\cdot(0.8+0.9+0.95+0.7+0.85) = 0.62$.
Apply penalty: $r = 0.5^{2} \times 0.62 = 0.25 \times 0.62 = 0.155$.
The exponential penalty quickly demotes candidates that miss any required removal, even if they excel elsewhere, enforcing the contract’s priority.
**Figure 3** Architecture of LensErase. LensErase follows a two-branch MMDiT architecture, where the image branch processes the noisy target latent and the condition branch processes the source latent. The proposed Mask-Aware RoPE incorporates the pooled binary mask into the condition branch by encoding masked and unmasked source regions along an additional modality dimension.
After generation, TraceFusion estimates the true edit region by detecting residuals between the generated and source images, then blends the generated content only inside this region while preserving the original source elsewhere.
Performance Benchmarks
LensErase sets new performance records on six public benchmarks.
LensErase reaches $30.82$ dB PSNR on LensErase‑Bench, a $+2.12$ dB gain over the next best method after RL.
Table 3 shows PSNR $30.82$ dB for LensErase versus $28.70$ dB for the runner‑up after reinforcement learning.
**Figure 7.** Qualitative comparisons with GPT-Image 2.5 and Flux2-Erase.
LensErase delivers state‑of‑the‑art performance across six public benchmarks and the challenging LensErase‑Bench.
Related Work
Survey of prior inpainting, editing, and object removal methods relevant to LensErase.
Early inpainting approaches propagated structure from hole boundaries or copied patches from visible regions. Recent learning‑based methods added semantic completion, adversarial supervision, gated convolutions, and explicit structural priors, while Fourier‑based models and mask‑aware Transformers expanded context for large, irregular masks.
Diffusion models provide strong generative priors for reconstructing missing content; inpainting variants constrain resampling, blend spatially, or add dedicated conditioning branches. Object‑removal work further introduces language or semantic control, masked‑region guidance, and calibrated diffusion pathways, while tools like ClickRemoval manipulate attention and EraseLoRA combine multimodal scene interpretation with test‑time optimization.
Datasets range from manually annotated triplets (MagicBrush) to fully synthetic pairs (RAA) and automated triplet mining (NoHumansRequired). Broader editing systems explore composition, object customization, and style‑content control (FreeStyle, iMontage), while CPAM and LBM focus on preserving context and fast translation. LensErase leverages a source‑mask interface and retains the intact source image to preserve effects and background, using TraceFusion to fuse generated content with the original outside the edit support.
Reward-Based Post-Training
We detail how we build and filter the diverse training data that powers LensErase.
LensErase unifies object, text, and watermark erasure by training on a large, carefully curated dataset; this section explains how each data source is constructed and filtered.
The model receives a fixed edit contract that describes what must be removed and what must be preserved, and five reward components evaluate the edit against that contract.
How does Contract‑Guided Reward Learning differ from ordinary diffusion reward learning?
Ordinary diffusion reward learning typically defines a reward per rollout without a shared contract, so each candidate is judged on its own terms. Contract‑Guided Reward Learning first fixes an edit contract (what must be removed, what must stay) and then evaluates every candidate against the same five criteria, feeding the result through a removal‑aware gate. This yields comparable rewards across candidates and focuses learning on the intended erasure behavior.
**Figure 6** Contract-guided reward construction for General Data. Source analysis establishes an erase contract shared across rollouts. Each candidate is evaluated against this fixed contract using semantic judgments and pixel fidelity. The five reward components are combined and passed through the removal-aware gate in Equation 6. The resulting rewards define group advantages for DiffusionNFT.
General Data (addition‑to‑removal) uses a teacher to add objects to real images, then recovers masks from the before/after pair via DCT‑low‑frequency and DINOv3 feature differences, refined with SAM2 prompts.
Alpha‑supervised watermark synthesis composites rendered logos or text onto clean images; the alpha channel directly yields the mask, guaranteeing precise watermark support.
Large‑foreground compositing generates isolated objects, places them on real backgrounds using YOLOE occupancy maps, and enforces mask‑area ratios between 20 %–60 % while limiting occlusion of existing content.
OCR‑verified partial visual‑text removal runs OCR on the source and edited images, selects groups of text polygons that disappear after editing, and blends the edited regions back into the source to form the target.
Layer‑aware poster rendering builds a stack of independent layers, removes a selected layer, and derives the mask from the RGB difference of the full‑layer and layer‑omitted renders.
SFT curation filters triplets for mask validity, edit correctness, and reconstruction quality, rejecting any pair with residual artifacts or ambiguous masks.
RL data combines 19 K tasks across domains, samples tasks by a fixed ratio, and scores difficulty with the weighted sum formula (Eq. 13); only Hard and Extreme tasks are kept for the difficulty‑filtered subset.
LensErase-Bench Evaluation
LensErase‑Bench quantifies erasure performance across diverse domains and difficulty levels.
LensErase‑Bench comprises 500 curated erasure cases across four domains.
200 General cases, 100 Poster, 100 Watermark, and 100 Visual Text, totaling $N=500$ cases.
A benchmark suite of 500 erasure scenarios that systematically vary mask size, target count, resolution, and difficulty across four content domains.
Mask‑area coverage is stratified per domain. General images are split into five bins (< 1 %, [1, 5) %, [5, 15) %, [15, 30) %, ≥ 30 %) with 40 cases each; Poster, Watermark, and Visual Text use three or four bins adapted to typical edit scales.
Attribute coverage complements mask‑area stratification. The General subset balances cases with/without visual effects and single‑ versus multi‑target removal. Poster cases span graphic, image, and text layers and three depth levels; Watermark cases span ten asset families, four layouts, four opacity ranges, and both precise and coarse masks; Visual Text cases include diverse languages, layouts, and backgrounds.
Difficulty and target count are annotated by GPT‑5.6 Sol. Across the benchmark, 59.2 % of cases have a single selected target and 40.8 % have multiple targets, with Watermark providing the densest multi‑target instances.
Resolution coverage preserves original aspect ratios without cropping or padding. The benchmark spans four long‑side ranges (≤ 1024, 1025–1280, 1281–1536, 1537–2047 px), each containing 125 cases: 50 General and 25 from each of Poster, Watermark, and Visual Text.
Evaluation follows a reference‑free protocol: judges see the source image, the source with selection overlay, the candidate output, and the binary mask. Scores (0–4) are assigned for Removal, Inpainting, Preservation, and Cleanliness, then scaled to 0–100.
**Table.** Attribute coverage. Beyond mask area, we curate complementary attributes that characterize practical erase requests. The General subset is evenly split between cases with and without associated visual effects, and between single-target and multi-target removal. Poster cases are approximately balanced across graphic, image, and text layers, as well as back, middle, and front layer depths. Watermark cases evenly cover ten asset families, four spatial layouts, four opacity ranges, and precise versus user-style coarse masks. Visual Text includes diverse languages, layouts, and background types.
**Resolution coverage.** All cases preserve their original aspect ratio and are normalized without cropping or padding. The benchmark spans four long-side resolution ranges, $\le 1024$, $1025-1280$, $1281-1536$, and $1537-2047$ pixels. Each range contains 125 cases: 50 General cases and 25 from each of Poster, Watermark, and Visual Text. This produces balanced resolution coverage across domains while retaining the original selection geometry.
Pretraining Design Ablations
Evaluating how initialization, mask conditioning, and training schedule affect LensErase performance.
We probe three design choices introduced in Section 3.1: (1) how the condition branch is initialized, (2) how the selection mask is injected via Mask‑Aware RoPE, and (3) whether a two‑stage freeze‑unfreeze schedule improves adaptation.
**Figure 5** Initialization and two-stage pretraining. Both visual branches are initialized from the pretrained Lens image branch. Stage 1 adapts the condition branch while freezing the image-specific backbone. Stage 2 jointly adapts both branches for removal and inpainting.
Post-Training and Inference
Describes fine‑tuning, reward construction, and the TraceFusion inference pipeline.
Supervised fine‑tuning (SFT) adapts the frozen backbone with rank‑$64$ LoRA adapters (scale $= 64$, dropout $= 0$) applied to the joint query/key/value and output projections of both image and text streams. The VAE and backbone remain unchanged, and the same mask‑conditioned flow‑matching loss from pretraining is used. Training runs for $5{,}000$ steps at a cosine‑scheduled learning rate of $2 \times 10^{-5}$, across six resolution buckets ($512$–$1792$) and nine aspect ratios.
Contract‑guided reward construction first builds an erase contract $K = (T, E, O)$ from the source image, mask and context, defining removal targets $T$, their visual effects $E$, and surrounding content $O$ that must stay intact. Each candidate edit is scored on Removal, Reconstruction, Preservation, Outside Fidelity and Cleanliness, with sub‑scores normalized to $[0,1]$ and weighted per‑component. The aggregated component score $P_{j,p}$ follows equation (17), and removal‑aware gating halves the base reward for every zero‑valued removal subcriterion (equation 6).
**Table 8.** Reward weights before applicability renormalization and removal-aware gating. The last column summarizes the General Data criteria. Poster, Watermark, and Visual Text share component weights, with reference-specific subcriteria described below.
Reward Prompt Excerpts clarify the semantic intent behind the VLM evaluator. For General Data the mask is treated as object‑selection evidence; any recognizable object whose main body is selected becomes a removal target, together with its shadows, reflections or contact traces. For Poster, Watermark and Visual Text the evaluation is guided by domain‑specific references, so protected content (e.g., logos in Watermark) is never penalized for remaining.
DiffusionNFT implementation computes a group‑relative advantage $A_j$ (equation 21) that is clipped to $[-5,5]$ and used to scale the RL advantage term. The RL objective (equation 23) combines the advantage‑weighted reconstruction loss with a small reference‑regularization term, and policy updates follow a momentum‑style exponential moving average (equation 25).
Inference uses a deterministic 20‑step Euler sampler (equation 26). The latent $z_1$ is drawn from a standard normal, then updated with $z_{t+\Delta t}=z_t+\Delta t\,v_\theta(z_t,t,z_{\text{src}};M)$ where $\Delta t<0$. After the final step the VAE decodes the terminal latent to produce the output image.
TraceFusion builds a data‑driven edit mask that fuses the original dilated mask with residual detections, then blends source and generated images using a distance‑based feather.
Compute the signed residual $\hat{I}_{\text{output}}-I_{\text{input}}$, which is $+20$ in the $2\times2$ block and $0$ elsewhere.
Apply a Gaussian blur ($\sigma=0.5$) to obtain $R$, which spreads the $+20$ values slightly into neighboring pixels.
Subtract the median of $R$ outside $M_{\text{dil}}$ (median $=0$), so $d(x)=R(x)$.
Threshold $d(x)$ at low $=4$ and high $=10$: the $2\times2$ block exceeds both thresholds, forming a high‑confidence component.
Extract the component (size $4$ pixels $\ge 8s^2$) and union it with $M_{\text{dil}}$ to get $S_0$ (which is the whole image in this toy case).
Apply the gamma transform ($\gamma=0.75$) to both images; the residual after gamma remains zero, so $S_\gamma$ is empty.
Fuse $S = S_0 \cup S_\gamma = $ whole image, compute the distance transform $d_S$, and obtain $\alpha(x)=1$ everywhere (no feathering needed).
Blend source and generated images using $\alpha$: the final output shows the $+20$ change only in the top‑left $2\times2$ block, exactly where the model edited.
TraceFusion isolates genuine edits by centering the residual and applying adaptive thresholds, so even when the dilated mask covers the entire image the blend only affects pixels where the model actually changed the content.
How is TraceFusion different from simply dilating the mask and blending the whole region?
Simple dilation blindly blends every pixel inside the expanded mask, regardless of whether the model altered it. TraceFusion first detects where the model’s output truly differs from the source (via Gaussian‑smoothed residuals and median offset), applies confidence thresholds, and adds a supplemental dark‑region pass. Only the union of the dilated mask and the data‑driven residual support is blended, so unchanged background stays untouched.
Extended Benchmark Results
LensErase’s performance on public erasure benchmarks compared to prior methods.
LensErase achieves the highest average PSNR of 34.96 across the four public erasure benchmarks.
Average PSNR values in Tables 10–13 show LensErase leading with 34.96, exceeding the next best method by over 2 dB.
We evaluate LensErase and twelve baselines on four public erasure benchmarks using eight metrics; Tables 10–13 report the full results.