Skip to content

enjeck/jpg2svg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jpg2svg

An attempt at converting colored JPG images to colored SVG. It automatically traces the image in layers and applies dominant colors selected from the image to each layer.

Some results (JPG and converted SVG side by side)

Images with higher contrast, and with white backgrounds produce better results:

Technical details

The actual image conversion code is held at svg.py. Below is a summary of the steps it follows:

  • Resizes the image to reduce processing time
  • Quantitizes the image to reduce the number of colors to work with
  • Calculates the luminance/brightness of dominant colors
  • Converts the JPG image to bitmap (since Potrace, used for tracing, only supports the Bitmap format)
  • Uses luminance values as thresholds for tracing the image into multiple layers
  • Converts the tracing to XML
  • Applies dominant colors to each of the layers
  • Groups the various layers into one SVG element