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.3.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.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vectorify-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 53ae8b0e1584a75835d250a44b6bb4834b87c87c152ffe61c43980006e2b4c5a
MD5 9fbcb76bbc0952fd017112b92328f248
BLAKE2b-256 ed5daba7ae57c6d81975ef83f31bbc7e9d3f78c6f29d8374f7cd2dc3a358502e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vectorify-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cfc93d7813be6cce8cece54597003e0a924d2f6282ba6b0dba13d41183f985c3
MD5 38e0257e1616c999c993dc4660d6108e
BLAKE2b-256 81e238a009a6889da7abfe41d475abc67ad124e7a3cfa3806b6a18fc5f5b907c

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