-1

I am looking for an optimized 4-connectivity or 8-connectivity Connected Component Labelling source code in MATLAB or C++. I saw many implementation of connected component labelling (4-connectivity) in MATLAB.

One of the implementations that works faster is the recursive implementation explained here: http://www.mathworks.com/matlabcentral/fileexchange/38010-connected-component-labeling-like-bwlabel

MATLAB has a built-in bwlabeln or bwlabel, which is far more optimized. They claim to use union-find method from two-pass algorithm described in Sedgewick's Algorithms in C, Addison-Wesley. However, it is hard to find any source code of it. Does anyone have idea about it? An optimized code is really needed.

Nasiba
  • 321
  • 2
  • 15

1 Answers1

1

You can indeed work by scanning the image in scanline order and when you meet a component seed-fill it.

You will find two efficient (and very similar) algorithms in Graphics GEMS 1:

  • A SEED FILL ALGORITHM, Paul S. Heckbert

  • FILLING A REGION IN A FRAME BUFFER, Ken Fishkin

and with a little effort some implementations. (The papers give Pascal-like code which is easy to translate.)

They run in linear time, use an explicit stack and don't require union-find.