SAMVG: A Multi-Stage Image Vectorization Model with the Segment-Anything Model

Haokun Zhu, Juang Ian Chong, Teng Hu, Ran Yi, Yu-Kun Lai, Paul L. Rosin

TL;DR

SAMVG is a novel multi-stage framework that leverages the Segment-Anything Model (SAM) to convert raster images into high-quality Scalable Vector Graphics (SVGs). By combining deep-learning-based segmentation with a novel "Filter by Impact" technique and iterative optimization, it achieves state-of-the-art results that are semantically meaningful and significantly faster than previous incremental methods.

What Problem Does This Paper Address?

Image vectorization—the process of converting pixel-based raster images into mathematical paths (SVGs)—is a long-standing challenge in computer graphics. While raster images lose quality when scaled, SVGs remain crisp at any resolution, making them ideal for logos and illustrations.

However, vectorizing complex photos or artworks is difficult. Existing methods generally fall into two camps:

  1. Direct Optimization: These start with a set of random shapes and "nudge" them to match the target image. They often get stuck in poor local minima or produce "patchy" results.
  2. Incremental Addition: Methods like LIVE add shapes one by one. While high-quality, they are computationally expensive and slow, often taking nearly an hour for a single complex image.

The authors identify a core bottleneck: initialization. If you don't start with shapes that correspond to actual objects in the image, the final SVG will lack semantic coherence and contain unnecessary complexity.

Methods

SAMVG introduces a four-stage pipeline designed to provide a semantically grounded starting point for vectorization:

  1. Retrieving Segmentation Masks: The model uses SAM’s Automatic Mask Generator to identify potential shapes. To ensure full coverage, it uses a circular convolution kernel to find "empty" regions in the initial mask set and re-prompts SAM to fill them.
  2. Filter by Impact: SAM often produces redundant or overlapping masks. The authors introduce a novel filtering method: they sort masks by area and add them to a canvas one by one. A mask is only kept if it significantly reduces the reconstruction error (MSE). This keeps the path count low while maintaining visual fidelity.
  3. Approximate Tracing & Optimization: The retained masks are converted into Bézier curves. This initial SVG is then refined using differentiable rendering (via DiffVG). The optimization uses a combination of Mean Squared Error (MSE), perceptual loss (LPIPS), and "Xing loss" to ensure paths don't self-intersect or become topologically messy.
  4. Identifying Missing Components: Small but vital details (like eyes in a portrait) are often missed in the first pass. SAMVG detects these by analyzing the error map between the current render and the target, re-prompting SAM for these specific coordinates, and performing a final optimization pass.
High-level overview of the SAMVG pipeline.

Datasets

The authors evaluated SAMVG on a self-collected dataset of 120 images. This dataset spans several distinct categories to test generalization:

  • WPAP: Stylized geometric portraits.
  • Scenery: Complex natural landscapes.
  • Subject: Focused objects or animals.
  • Art: Various painting styles.
  • Emoji: Simple, clean graphics.

They compared their results against two primary baselines: DiffVG (pure optimization) and LIVE (incremental optimization).

Key Insights and Ideas

  • Semantic Initialization is King: By using SAM, the model starts with paths that actually represent "things" (leaves, eyes, clouds). This leads to SVGs that look more natural to humans compared to the random patches generated by pure optimization methods.
  • The "Filter by Impact" Efficiency: The ablation study showed that without this filter, the number of paths triples and processing time quadruples, yet the image quality barely changes. This highlights that most generated masks are redundant.
  • Closing the Gap on Small Details: The multi-pass approach (Stage 4) is crucial. Large-scale segmentation models like SAM often overlook tiny semantic details in a global pass; targeted re-prompting based on error maps effectively solves this.

Examples of failure cases (uncovered and redundant regions) that the filtering and re-prompting stages address. (Note: Figure 3 in the paper illustrates these failure cases).

Examples of failure cases (uncovered and redundant regions) that the filtering and re-prompting stages address.

Key Results

SAMVG demonstrates a superior balance of speed and quality:

  • Speed: SAMVG processes images in roughly 139 seconds, nearly 19x faster than LIVE (~2609 seconds), while maintaining similar or better quality.
  • Quality: It consistently achieved the lowest LPIPS (perceptual similarity) and FID (distributional similarity) scores across the dataset, indicating results that are more visually pleasing and accurate to the source.
  • Complexity: SAMVG produced SVGs with fewer paths and parameters than baselines, making the resulting files more efficient.
Qualitative comparison showing SAMVG's ability to capture semantic features better than DiffVG and LIVE.

Limitations and Future Work

While the paper presents a significant step forward, a few areas remain open for exploration:

  • Reliance on SAM: The quality of the initial trace is heavily dependent on SAM’s ability to segment the image. In extremely abstract or low-contrast images, SAM might struggle to provide a good foundation.
  • Optimization Iterations: Although much faster than LIVE, 139 seconds is still not "instant." Further work could explore reducing the number of optimization iterations required through better curve initialization.
  • Color Gradients: The current model focuses on flat-colored Bézier paths. Extending this to support complex gradients within the SAM-segmented regions could further improve realism for photographic content.

Summary updated

BibTeX
@inproceedings{zhu2024samvg,
  author = {Haokun Zhu and Juang Ian Chong and Teng Hu and Ran Yi and Yu-Kun Lai and Paul L. Rosin},
  title = {{SAMVG: A Multi-Stage Image Vectorization Model with the Segment-Anything Model}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2024},
  url = {https://openreview.net/forum?id=rLXxZYzoL2},
}
Figure