DiffusionPen: Towards Controlling the Style of Handwritten Text Generation

Konstantina Nikolaidou, George Retsinas, Giorgos Sfikas, Marcus Liwicki · DOI

TL;DR

This paper introduces DiffusionPen, a novel approach for generating realistic handwritten text that precisely controls both the content and the writer's style, even for styles not seen during training. By leveraging latent diffusion models and a unique hybrid style extractor, DiffusionPen offers a significant leap in controlling handwriting generation, with implications for data augmentation in handwriting recognition.

What Problem Does This Paper Address?

Generating realistic handwritten text that accurately reflects both the intended message and a specific writer's unique style is a complex challenge. This is due to the inherent variability in human handwriting, the vast number of character combinations, and the difficulty in capturing subtle stylistic nuances. While diffusion models have shown promise, they remain underexplored for this task, particularly in controlling style for unseen writers. Existing methods often struggle with style diversity and can produce artifacts. This paper aims to address these limitations by developing a method that can generate high-quality, diverse handwritten text with fine-grained style control, even in a few-shot setting.

Methods

DiffusionPen is built upon Latent Diffusion Models (LDMs), which operate in a compressed latent space for efficiency. The core innovation lies in its hybrid style extractor. This extractor combines metric learning (specifically, a triplet loss) with classification to create a robust and continuous style embedding space. This approach ensures that points in the style space correspond to meaningful and distinct writing styles, promoting diversity. The model uses a few-shot learning paradigm, requiring only a small number of example images (k=5) from a target writer to learn their style. A CANINE-C text encoder is used to handle textual content, allowing for the generation of out-of-vocabulary (OOV) words. The authors also explore various style variation strategies, including interpolation between styles and mixing multiple styles, as well as injecting noise into the style embedding to further enhance diversity.

Datasets

The primary dataset used for training and evaluation is the IAM Offline Handwriting Database. This dataset contains a large number of isolated words and their transcriptions from various writers. For training the style encoder and the diffusion model, a subset of 339 writers was used, with 160 writers reserved for evaluating unseen styles. The GNHK dataset was also used to showcase qualitative results on unconstrained, camera-captured English handwritten text.

Key Insights and Ideas

  • Hybrid Style Extraction is Key: Combining metric learning and classification for style extraction creates a more robust and diverse style representation space than either method alone. This is crucial for capturing subtle stylistic variations and avoiding mode collapse.
  • Few-Shot Learning for Style: The ability to learn a writer's style from just five examples is a significant advancement, making the model practical for scenarios with limited data.
  • Controlling Style Diversity: DiffusionPen's exploration of style interpolation and multi-style mixtures demonstrates a powerful ability to generate novel styles and variations, moving beyond simply mimicking existing ones.
  • Augmenting HTR Data: Generated data from DiffusionPen can significantly improve the performance of Handwriting Text Recognition (HTR) systems, highlighting its practical utility.

Key Results

  • State-of-the-Art Performance: DiffusionPen outperforms existing methods (GANwriting, SmartPatch, VATr, WordStylist) both qualitatively and quantitatively across various metrics, including FID, MSSIM, RMSE, and LPIPS.
  • High Classification Accuracy: The model achieves a writer identification accuracy of 70.31% on generated samples, surpassing the previous best of 68.25% from WordStylist.
  • Improved HTR: When used to augment the IAM training set for HTR, DiffusionPen-generated data leads to a significant reduction in Character Error Rate (CER) and Word Error Rate (WER), achieving results close to using the real IAM training data. For instance, it achieved a CER of 6.94% and WER of 18.11% in imitation experiments.
  • Qualitative Success: The method successfully generates realistic handwritten samples for both seen and unseen styles, as well as for in-vocabulary and out-of-vocabulary words, including digits and special characters.

Limitations and Future Work

  • Rare Character Combinations/Ligatures: The model may struggle with very rare character combinations or complex ligatures in certain cursive styles.
  • Length Limitations: There's a length limit for generated words, influenced by the maximum word length in the training data and noise initialization. The authors suggest patching smaller word segments as a solution.
  • Future Work: The authors suggest further exploration of style and noise variation in different stylistic aspects. They also highlight the potential for using DiffusionPen for large-scale dataset generation to aid HTR training. The ability to control the number of style samples used for conditioning during sampling is also noted as a promising direction.

Summary updated

Abstract

Handwritten Text Generation (HTG) conditioned on text and style is a challenging task due to the variability of inter-user characteristics and the unlimited combinations of characters that form new words unseen during training. Diffusion Models have recently shown promising results in HTG but still remain under-explored. We present DiffusionPen (DiffPen), a 5-shot style handwritten text generation approach based on Latent Diffusion Models. By utilizing a hybrid style extractor that combines metric learning and classification, our approach manages to capture both textual and stylistic characteristics of seen and unseen words and styles, generating realistic handwritten samples. Moreover, we explore several variation strategies of the data with multi-style mixtures and noisy embeddings, enhancing the robustness and diversity of the generated data. Extensive experiments using IAM offline handwriting database show that our method outperforms existing methods qualitatively and quantitatively, and its additional generated data can improve the performance of Handwriting Text Recognition (HTR) systems. The code is available at: https://github.com/koninik/DiffusionPen. This paper was accepted at the 18th European Conference on Computer Vision ECCV 2024 (LNCS volume 15143, pp. 417–434, 2025) and is available at: https://link.springer.com/chapter/10.1007/978-3-031-73013-9_24 Keyword: Vision and Learning
BibTeX
@inproceedings{nikolaidou2024diffusionpen,
  author = {Konstantina Nikolaidou and George Retsinas and Giorgos Sfikas and Marcus Liwicki},
  title = {{DiffusionPen: Towards Controlling the Style of Handwritten Text Generation}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-73013-9\_24},
}
Figure