Introduction

As discussed in the comments the way he achieved it was not the fastest way to achieve the below result

Background

There is a far faster way which is to do a one pass seperation of the image using a tecnique discussed
in "A Linear-Time Component-Labeling Algorithm Using Contour Tracing Technique" by Fu Chang, Chun-Jen Chen,
and Chi-Jen Lu (www.iis.sinica.edu.tw/papers/fchang/1362-F.pdf).

From the article I developed C code which is presented here.

Using the code

The use of the code is fairly straight forward to use load a bitmap (I have included a few samples) and then choose the vectorize function.
There are several play around options to display different features, zoom etc.

The code is fairly well documented and the original PDF work should provide any background information that is required.

In the load bitmap section on the demo I have simply done a black/white
separation based on the grayscale value of the image.
In many instances the user may require more than two color seperation and they would need to modify and provide there own color reduction code.

Comments and Discussions

Thank you for providing the code to the community. Recently, I ported the code to JavaScript and want to publish it as part of a bigger project (under MIT License). Is it enough to add a reference to this publication in the source code?