Is there any library for converting a raster image to a vector one limiting the number of sampled colours to a specific set? Something like what is done in VectorMagic but giving a subset of colours to be used.
Raster to vector conversion library
9.7k Views Asked by Claus At
2
There are 2 best solutions below
0

Imagetracer is a free and open source (Public Domain) library and application which might be useful. Disclaimer: I made these.
If you need a command line application, I recommend ImageTracer.jar from
https://github.com/jankovicsandras/imagetracerjava
with options like these
java -jar ImageTracer.jar input.png outfilename output.svg numberofcolors 4
to limit the number of colors to 4. If you call the library from a Java program, you can use custom palette, and there are many other options.
You can use the JavaScript version from the browser or with Node.js: https://github.com/jankovicsandras/imagetracerjs
There is the opensource library/program potrace which performs a fine vectorization. The thing is it first converts the input image into a luminensce one, and then binarize it. This step is optional, made by a separate program, so you can use potrace but in a different manner, by constructing yourself several versions of binarized images. I think VectorMagic builds its contours based on the gradient/laplacian of the input image, that's why you cannot impose any set of colours.
If you have a subset of colours to be used as input, I advise you to folow the following algorithm:
At the end, you will get a set of contours. Maybe the contours would not match exactly, but there would be sufficiently close to let you simplify them and delete properly doublons of contours.