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

Uploaded Python 3

File details

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

File metadata

  • Download URL: vectorify-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 631755c55011c0b8112dea8aa7867d4e83c2ef6f33e2c00d55f6c2fef7bdf115
MD5 fa879708404f1bb01f1a535d6e7f81a0
BLAKE2b-256 b70bf8b45dcfd7a3a4d1b727291fb16b399a4e3b56bdccd78e5a9038bad104e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vectorify-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aad92a3ab344827e9902474a7788146d41750e4b6b721e4da14201749a4e2d5c
MD5 3b38936e24c092d3c9bcbce463eecd4b
BLAKE2b-256 8e1171e45b1cca74b2ee2cd79985b2ba84dd507db892ba9e4c902f5f83781845

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