To the best of my knowledge, Inkscape (potrace) is the most readily available tool for converting the bitmap images from POV-ray to SVG. There are a few things to look out for, but this is still really easy:
1) Remove all reflection and shading from the textures (colors) in the POV-ray scene. Work on getting even lighting for the whole scene. Generate the scene without antialiasing (jagged edges are fine, and even desired).
2) Follow the directions here for tracing the SVG drawing.
Now to use the standard library's xml.etree.ElementTree package to get at the colors. Before jumping in, I first removed any references to the old bmp image from POV-ray and checked on the three color values in the SVG file.
The three colors in the image are #fefefe (slightly off white), #000000 (black), and #00fd00 (light green).
Manipulation of colors in an SVG image.
from xml.etree import ElementTree as ET
def drilldown(nodex, oldcolor, newcolor):
Walk node of element tree in search
Replace oldcolor with newcolor where
childrenx = nodex.getchildren()
for childx in childrenx:
drilldown(childx, oldcolor, newcolor)
itemsx = nodex.items()
for itemx in itemsx:
if itemx.find(oldcolor) > -1:
oldcolorstr = itemx
newcolorstr = oldcolorstr.replace(oldcolor, newcolor)
def changecolor(oldcolor, newcolor, filename):
Replaces oldcolor with newcolor in an
SVG file named filename.
All three arguments are strings.
oldcolor and newcolor are hex strings
in the format #xxxxxx.
# the colors are at the lowest level
# in the XML (SVG) file
# drill down until they are reached
svgobj = ET.parse(filename)
rootx = svgobj.getroot()
drilldown(rootx, oldcolor, newcolor)
Python 2.5.4 (r254:67916, Aug 9 2010, 08:57:51)
[GCC 4.2.1 20070719 ] on openbsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> import svgchangecolor as svgcc
>>> svgcc.changecolor('#00fd00', '#ffff00', 'crossdroppullegg.svg')
>>> svgcc.changecolor('#000000', '#00aa00', 'crossdroppullegg.svg')
>>> svgcc.changecolor('#fefefe', '#000000', 'crossdroppullegg.svg')
There are only three elements with color in the file (the dark green one is doing all the "work" of filling in the pattern). The script is really overkill in this case. For a drawing with a number of separate paths with the same color, though, this could be very useful.