TL;DR
TransRef is a novel transformer-based framework for reference-guided image inpainting that leverages a similar reference image to fill in complex missing regions. By combining a multi-scale hierarchical architecture with specialized modules for local alignment and global attention, it significantly outperforms existing methods in both visual quality and computational efficiency.
What Problem Does This Paper Address?
Traditional image inpainting—filling in missing or corrupted parts of an image—usually relies on the surrounding context. While this works for simple patterns, it often fails when holes are large or the scene contains complex semantic information (like a specific face or intricate architecture). In these cases, models often produce blurry or semantically incorrect results.
Reference-guided inpainting attempts to solve this by providing a "cheat sheet": a reference image of the same scene taken from a different viewpoint or at a different time. However, this introduces a new "ill-posed" challenge: the reference image and the corrupted image rarely match perfectly in terms of geometry, lighting, or style. Existing methods struggle to align these two images accurately, especially when the corrupted region is large and lacks structural cues.
Methods
The authors propose TransRef, a transformer-based encoder-decoder network that progressively embeds reference information across multiple scales.
The core of the system lies in two novel modules within the "Reference Embedding" procedure:
- Reference-Patch Alignment (Ref-PA): This module handles local, coarse alignment. It uses deformable convolutions to learn an offset map that spatially warps the reference features to match the target. It also includes a Patch Harmonization (PH) block that uses channel attention to bridge the style gap between the two images, ensuring the textures look natural when fused. The Ref-PA module, consisting of a Patch Alignment (PA) block and a Patch Harmonization (PH) block.
- Reference-Patch Transformer (Ref-PT): Local alignment isn't always perfect. To fix remaining misalignments, the Ref-PT uses a multi-head reference-attention mechanism. Unlike standard self-attention, this module treats the aligned target features as the "Query" and the reference features as the "Key" and "Value," allowing the model to globally search the reference image for the best-fitting content. Comparison between the standard Main-Patch Transformer (Main-PT) and the proposed Reference-Patch Transformer (Ref-PT).
Datasets
To train and evaluate TransRef, the authors introduced DPED50K, a large-scale benchmark containing 50,000 training pairs and 2,000 test pairs. These pairs consist of real-world photos (street scenes, houses, plants) matched using SIFT features to ensure high similarity.
The model was also tested on:
- RealSet: A dataset for real-world object removal.
- Satellite Imagery: For the task of cloud removal using multi-temporal images of the same landscape.
Key Insights and Ideas
- Transformers over CNNs: The authors argue that transformers are inherently better for inpainting because their self-attention mechanism can capture long-range pixel correlations, which is vital for maintaining global consistency across large holes.
- Local-to-Global Alignment: By first performing local spatial warping (Ref-PA) and then global attention-based refinement (Ref-PT), the model handles both geometric distortions and semantic mismatches more robustly than single-stage methods.
- Efficiency Matters: Despite using transformers, TransRef is designed to be efficient. It uses a "convolution tail" in the decoder for fast upsampling and local texture refinement, resulting in significantly lower FLOPs and faster inference times than many SOTA competitors.
Key Results
TransRef demonstrates a clear lead over both context-based (e.g., LaMa, ZITS) and reference-based (e.g., RGTSI, Uni-paint) methods:
- Quantitative: In cases with large masks (40-60% corruption), TransRef achieved a PSNR gain of over 3dB compared to the next best baseline.
- Qualitative: The model excels at restoring sharp edges and novel patterns (like text or faces) that context-only models simply cannot guess.
- Computational: TransRef is remarkably lightweight, requiring only 7.55G FLOPs compared to 182.73G for ZITS and 146.67G for RGTSI, while being roughly 3x faster in inference than ZITS.
Limitations and Future Work
The authors note that TransRef still struggles with highly repetitive textures or extremely fine structures (like dense brick joints or tiny text) that are difficult to align perfectly. If the alignment fails at a very granular level, the output can exhibit minor semantic flaws or artifacts. Future work will likely focus on even more robust feature alignment techniques and exploring no-reference quality assessment to better judge the "authenticity" of the restored regions.
Summary updated