Beyond Pixels: Exploring Human-Readable SVG Generation for Simple Images with Vision Language Models

Tong Zhang, Haoyang Liu, Peiyan Zhang, Yuxuan Cheng, Haohan WangarXiv 2023 · DOI

Introduction

Traditional image vectorization often prioritizes pixel-perfect reconstruction at the expense of code clarity. The resulting "spaghetti code"—comprising thousands of overlapping paths—is virtually impossible for humans to edit or for Large Language Models (LLMs) to interpret. This research introduces $S^2VG^2$ (Simple-SVG-Generation), a framework designed to bridge the gap between visual fidelity and semantic interpretability by generating concise, human-readable XML.

Semantic decomposition of a raster image into human-readable SVG code

The $S^2VG^2$ Framework

The authors propose a two-stage pipeline that combines the semantic reasoning of Vision Language Models (VLMs) with the mathematical precision of differentiable rendering.

The S2VG2 two-stage pipeline: VLM-based shape configuration followed by DiffVG-based parameter refinement.
  1. The Architect (VLM Stage): A modified BLIP model uses a Vision Transformer (ViT) to encode the image and a BERT-based decoder to generate SVG code. This stage leverages the model's pre-trained semantic understanding to identify shapes and their logical relationships.
  2. The Polisher (Refinement Stage): Since VLMs often struggle with precise coordinate placement, the system employs DiffVG, a differentiable renderer. By calculating the pixel comparison loss between the rendered SVG and the original image, the system uses gradient descent to fine-tune shape parameters like size, position, and rotation.

Key Insights: SVG as Language

The core innovation lies in treating SVG generation as a translation task. By framing the problem as "Image-to-XML," the researchers leverage the reasoning capabilities of modern VLMs. This approach recognizes that an SVG's utility depends on its simplicity; a file with 10 discrete shapes is far more valuable for downstream AI reasoning or human design than one with 1,000 redundant paths. This hybrid approach uses the VLM for the "logic" and DiffVG for the "math," bypassing the inherent quantitative limitations of current transformer architectures.

Experimental Results

The $S^2VG^2$ model was evaluated using two new datasets: SVG-SHAPE (50,000 pairs for VQA) and SVG-Transform (500,000 pairs for geometric reasoning).

  • Conciseness: $S^2VG^2$ produced SVGs with an average of 186 tokens, a massive reduction from the 3,624 tokens required by existing methods like LIVE.
  • Visual Reasoning: When the generated code was processed by GPT-4 for visual question answering, $S^2VG^2$ achieved 87.75% accuracy, nearly matching ground-truth performance (87.72%) and far outperforming previous methods that hovered around 50%.
  • Human Interpretability: In user studies, 85.8% of participants preferred $S^2VG^2$ outputs for their ease of understanding and editability.

Conclusion and Future Directions

While $S^2VG^2$ excels at simple geometric scenes, challenges remain in scaling to highly complex images with thousands of elements or intricate textures. Future work aims to create a fully end-to-end system where visual loss directly trains the VLM, potentially unlocking even higher precision and the ability to handle more complex patterns.

Summary updated

BibTeX
@misc{zhang2023beyond,
  author = {Tong Zhang and Haoyang Liu and Peiyan Zhang and Yuxuan Cheng and Haohan Wang},
  title = {{Beyond Pixels: Exploring Human-Readable SVG Generation for Simple Images with Vision Language Models}},
  year = {2023},
  eprint = {2311.15543},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.15543},
}
Figure