Vectorization

The vectorization module provides functionality to convert raster images into vector sketches. This is useful for tasks that require stroke-level information from pixel-based inputs.

Source: tests/test_vectorization.py

Available Methods

The module currently supports the following methods:

sketchkit.vectorization.DeepVecSIG24([device])

A class for image vectorization using the method of paper "Deep Sketch Vectorization via Implicit Surface Extraction" in SIGGRAPH 2024.

sketchkit.vectorization.LineDrawer([method, ...])

Native LineDrawer integration that mirrors the structure of other vectorizers.

Deep-Sketch-Vectorization

The method implements Deep Sketch Vectorization via Implicit Surface Extraction from SIGGRAPH 2024, which is a fast and accurate vectorization method that can turn clean raster line drawings with complex topology into high quality vector graphics. The method is capable of handling high valence star-junctions.

Additional Outputs: After using the code above, a final.svg denoting the vector image and its corresponding stroke visualization vis.svg can be found in the svg folder in the same directory as the script.

LineDrawer

LineDrawer (LineDrawer: Stroke-Level Process Reconstruction of Complex Line Art Based on Human Perception) is a stroke-level vectorization method based on human perception, presented in Computers & Graphics 2025. The method implements the CNNVE (CNN-based Vectorization Engine) approach to reconstruct complex line art at the stroke level.

The LineDrawer vectorization pipeline consists of the following steps:

  1. Skeletonization: Converts the input image into a skeleton representation.

  2. Graph Building: Constructs a pixel-level graph from the skeleton.

  3. Graph Simplification: Merges edges to create simplified graph structures.

  4. Stroke Extraction: Uses deep learning to extract stroke masks from the graph.

  5. Stroke Merging: Combines stroke masks to produce the final vectorized output.

Code

The main interface is the Vectorizer class.

from sketchkit.vectorization import Vectorizer
import numpy as np
from PIL import Image

# Load an input image
img = np.array(Image.open("input.png").convert("L"))

# Initialize the vectorizer with LineDrawer method
vectorizer = Vectorizer(method="LineDrawer", device="cuda") # or method="DeepVecSIG24"

# Run vectorization
sketch = vectorizer.run(img)

# Access the vectorized paths
print(f"Number of paths: {sketch.path_num}")
print(f"Total curves: {sketch.curve_num}")

# Save to an SVG file
sketch.to_svg(filename="vectorization.svg")