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

ive am

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: vectorify-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a016a9e5f5f7627b8e86ef2739e3fdfc41fde7d1f7c4a655102b347262d08595
MD5 f5ee8953d2b34dc923f59c254e541813
BLAKE2b-256 caddbb892d3ffe49f0b3fa1dbd1af7ebf764923adf024462a4a56e0c7d569ee6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vectorify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb72213e190d7cf23b4cc1b9b3efa0669e6f8a79983b7e03b1b2ad77c2da18df
MD5 f809a5265b5732a45415f86ab5d86e46
BLAKE2b-256 1ca67315c693b0b6551c9db41be1cbc04e77de2f74fc13b055b09769ff4a7b4a

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