Domanda

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.

È stato utile?

Soluzione 2

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:

  • for each colour of the input subset of colours, find the subspace of the colour space which is "nearest" from the selected colour than from any other colour. Something like an algorithm computing the Voronoi partition of the input subset would do the job quite well at once; use for example qhull for that.
  • for each subspace, binarize the input image, drawing every pixel white if inside the subspace and black otherwise. Then apply potrace's or VectorMagic's vectorization on it.

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top