Introduction
Omar Gamil created an article on connected component labeling
(http://catalog.codeproject.com/Articles/336915/Connected-Component-Labeling-Algorithm).
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.
HDC load_bmp(char* BMPName){
unsigned char i;
int x, y;
HBITMAP Bmp;
BITMAP bm = {0};
HDC Dc;
COLORREF Col;
CleanUp(); Bmp = (HBITMAP) LoadImage(GetModuleHandle(NULL), BMPName,
IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION); if (Bmp == 0) return (0); GetObject(Bmp, sizeof(bm), &bm); if ((bm.bmWidth > 32765) || (bm.bmHeight > 32765)){ MessageBox(0, "Bitmap is too large", "BITMAP ERROR", MB_OK); return(0); }
Dc = CreateCompatibleDC(0); SelectObject(Dc, Bmp); FirstImage = CreateCCLMap2D((short)(bm.bmWidth+2),
(short)(bm.bmHeight+2), 0);
for(y = 0; y < bm.bmHeight; y++){ for(x = 0; x < bm.bmWidth; x++){ Col = GetPixel(Dc, x, y); if (RGB_To_GreyScale(Col) < 128) i = 1; else i = 0; FirstImage->map[y+1][x+1] = i; };
};
DeleteObject(Bmp); return Dc; };