Converting From Raster-Based To Vector-Based Graphics With the GIMP and Sodipodi


Required Software


You need GIMP 1.2, and a version of Sodipodi that doesn't crash when it loads complicated SVG files.  I have included the source of a snapshot that works here.

And of course, my scripts. You'll have to run 'make' if on a platform other than Red Hat 7.1

First Things


First of all copy the .scm files to your .gimp-1.2/scripts directory.  Then load up the GIMP, or if it is already loaded, do Xtns->Script-Fu->Refresh.

Drawn Images

Coloured Images


Say you have an image like this:
sample image
Select Script-Fu->Alchemy.  You should see 3 options, Cartoon, Cartoonify, and Cartoonify-Greyscale.  Choose Cartoonify.  This will create a number of paths.  You can see them by choosing the Paths tab in the Layers dialog.  Cartoonify tries to create paths in the following order:
white, light grey, dark grey, black, red, light red, dark red, green, light green, etc.  Sometimes it cannot find any pixels that satisfy a certain coulour.

The next steps can be a little labour intensive, so Jesper Zedlitz has written some Gimp plugins in Perl to automate the process.
svg.pl save_paths.pl

In the Layers dialog select each path and export it.  You can save work if you name them in the following way:
color
filename
white
wh1.path
light grey
wh2.path
dark grey
wh3.path
black
wh4.path
red
re1.path
light red
re2.path
dark red
re3.path
green
gr1.path
light green
gr2.path
dark green
gr3.path
blue
bl1.path
light blue
bl2.path
dark blue
bl3.path
yellow
ye1.path
light yellow
ye2.path
dark yellow
ye3.path
cyan
cy1.path
light cyan
cy2.path
dark cyan
cy3.path
magenta
ma1.path
light magenta
ma2.path
dark magenta
ma3.path
Next step is converting the GIMP path formatted files to SVG files.  If you haven't compiled gimp2sodi.cpp to g2s, do so now.  In the foreach script, there's a number on the third line, this number tells the cleaner script to delete shapes with fewer than that many verticies.  Change it if you want, I find 5 is a good value.  Now run the foreach script in the same directory where you stored those .path files.  Make sure g2s and cleaner.py, and stitcher.py are in that directory too.  Run foreach.  You should now have a bunch of svg files including one called master.svg.  Open them in Sodipodi and play around, giving you something like this:
what it looks like in sodipodi

Greyscale Images.


Basically the same process, but instead of using Cartoonify, you use Cartoonify-Greyscale
raster vector


Photographs


Basically the same as Coloured Images, except it requires more playing around with in Sodipodi.

Tip: you get more detail in you vector image if you scale up the size of your original raster image.
portrait vect vect

Thanks

Thanks go out to all the GIMP and Sodipodi developers, Simon Budig and Lemmit Toomet.

Contact

shandy@geeky.net