Improving Diffusion Models for Scene Text Editing with Dual Encoders

Jiabao Ji, Guanhua Zhang, Zhaowen Wang, Bairu Hou, Zhifei Zhang, Brian L. Price, Shiyu Chang

Abstract

Scene text editing involves modifying or inserting text into images while maintaining environmental consistency in lighting, perspective, and texture. While Diffusion Models have set new standards for image generation, they frequently struggle with accurate character rendering and specific style adherence. This paper introduces DiffSTE, a novel framework that addresses these limitations through a dual-encoder architecture and instruction-based tuning. By integrating a character-level encoder with a CLIP-based instruction encoder, DiffSTE ensures precise spelling and robust style control, significantly outperforming existing GAN and diffusion-based methods.

Introduction

Modifying text within a scene is a complex generative task. It requires not only changing the semantic content but also harmonizing the new text with the original image's physical properties. Traditional Generative Adversarial Networks (GANs) often produce blurry results or fail at text insertion. Conversely, standard Diffusion Models, which utilize sub-word tokenizers like CLIP, often fail to render individual characters correctly, leading to illegible "spaghetti text." Furthermore, these models lack the fine-grained control needed to follow specific stylistic instructions.

Methodology: The DiffSTE Framework

The authors propose a two-pronged approach to solve the "spelling and style" problem in scene text editing.

1. Dual-Encoder Architecture

DiffSTE replaces the single text encoder of standard Stable Diffusion (SD) with a dual-encoder system:

  • Instruction Encoder ($Enc_{inst}$): A CLIP-based encoder that interprets natural language prompts to capture the overall style and "vibe" (e.g., "grass-colored font").
  • Character Encoder ($Enc_{char}$): A specialized module that processes the target text as a sequence of discrete characters. This provides the model with an explicit map for spelling and text length.
  • Feature Fusion: During the denoising process, the model attends to both encoders, merging their outputs to guide the generation of text that is both stylistically appropriate and orthographically correct.

2. Instruction Tuning

Borrowing from Large Language Model (LLM) methodologies, the authors implemented instruction tuning. They trained the model on a pipeline that maps specific linguistic instructions (e.g., "Write 'TEXT' in color: COLOR") to visual outputs. This allows the model to translate complex semantic descriptions into precise pixel-level modifications.

Experimental Setup and Datasets

The model was trained on a synthetic dataset of 1.3 million examples created with the Synthtiger engine, encompassing 100 font families and nearly 1,000 colors. Evaluation was conducted on five real-world benchmarks: ArT, COCOText, TextOCR, ICDAR13, and ICDAR15, representing diverse "in-the-wild" text scenarios.

Key Results and Insights

DiffSTE demonstrates a significant leap in performance over both GAN-based and vanilla diffusion models.

Comparison of scene text editing results: Input, Rendered text, Mostel (GAN), SD (Standard Diffusion), and DiffSTE.
  • Superior Accuracy: In style-free editing tasks, DiffSTE achieved a 64% improvement in OCR accuracy compared to the Mostel GAN baseline.
  • Zero-Shot Generalization: The model can interpolate between fonts and apply transformations (like italics) to fonts it has never encountered in training.
  • Semantic Style Control: Through instruction tuning, the model understands semantic color mappings, such as "eggplant" or "springtime tree," translating these concepts into accurate visual styles.
  • Human Preference: Human evaluators preferred DiffSTE's outputs by a margin of 28% over competitors, citing higher image naturalness and legibility.

Conclusion and Future Directions

DiffSTE successfully bridges the gap between high-quality image generation and precise text rendering. However, challenges remain. The current $256 \times 256$ resolution limit necessitates scaling for high-definition applications. Additionally, the model's reliance on surrounding context for style inference suggests that improving synthetic training data realism could further enhance performance. Finally, the authors highlight the importance of developing watermarking safeguards to prevent the potential misuse of high-fidelity text editing for forgery.

Summary updated

BibTeX
@article{ji2024improving,
  author = {Jiabao Ji and Guanhua Zhang and Zhaowen Wang and Bairu Hou and Zhifei Zhang and Brian L. Price and Shiyu Chang},
  title = {{Improving Diffusion Models for Scene Text Editing with Dual Encoders}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2024},
}
Figure