Skip to main content

Convert raster images (PNG, JPG, BMP, WebP) to simplified SVG vector graphics using k-means colour quantization and contour tracing.

Project description

logo for vectorify

Convert raster images (PNG, JPG, etc.) into simplified SVG vector graphics using k-means colour quantization and contour tracing.

Installation

Requires Python 3.11+.

uv sync

Usage

uv run vectorify generate <filepath> <output> [options]

Example

uv run vectorify generate photo.png ./output.svg --n_colors 8 --smooth 2 --simplify 0.5

Update README images

Regenerate all example SVGs, PNGs, and grid images used in this README:

uv run vectorify update-readme

Arguments

Argument Type Description
filepath string Path to the input image
out_dir string Directory for the output SVG

Options

Option Type Default Description
--n_colors int 8 Number of colours to quantize the image into
--median_size float 5 Median filter kernel size for label smoothing (0 = disabled)
--min_region float 50 Minimum connected region size in pixels (0 = disabled)
--smooth float 2 Gaussian smoothing sigma applied to contours (0 = disabled)
--simplify float 0.5 RDP simplification epsilon in pixels (0 = disabled)
--buffer float 1 Outward normal offset to expand shapes and fill gaps

Configuration

buffer

Expands each shape outward along its edge normals by the given pixel amount. Eliminates sub-pixel gaps between adjacent colour regions caused by smoothing or simplification.

buffer example


median_size

Applies a median filter of this kernel size to the label map. Fills small holes, removes straggler pixels, and smooths region boundaries. Larger values produce more aggressive cleanup.

median_size example


min_region

Removes connected components smaller than this many pixels, replacing them with their most common neighbouring colour. Catches isolated specks that the median filter misses.

min_region example


n_colors

Number of distinct colours the image is quantized into via k-means clustering. Lower values produce a more simplified, poster-like result.

n_colors example


simplify

Epsilon value for the Ramer-Douglas-Peucker algorithm. Reduces the number of vertices in each contour path. Higher values = fewer vertices = simpler shapes.

simplify example


smooth

Gaussian smoothing sigma applied to contour vertices. Rounds off jagged pixel-aligned edges into flowing curves. Applied before simplification.

smooth example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vectorify-0.1.1.tar.gz (5.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vectorify-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file vectorify-0.1.1.tar.gz.

File metadata

  • Download URL: vectorify-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for vectorify-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5228ec68362c6edd14dc0b68fd945d4fb207e9033f6294c33be791ad4b4319d9
MD5 45034b2565e891bfc689b8795d0c4009
BLAKE2b-256 a1d47305d2c2859c9cf961225d4447f3a3fd26f1233abba18542ac01e3e7525a

See more details on using hashes here.

File details

Details for the file vectorify-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vectorify-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for vectorify-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f689dae4b61c45e901cbe0eba4268371d12c7a53639086972e7f9954c1874f5
MD5 af5b9a2aa32f04e452027dd9da0f1359
BLAKE2b-256 23633ddd6bd489ebc57092b990c76cb0c8567e81d2e43d2607f6ba80670f8bdc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page