以 black-white and 8-connectivity 为例,0代表背景,1代表前景物体。该算法包括 two scans, from left to right and from top to down.
The first scan: examine the four neighbors(斜左上角,正上方,斜右上角和左方)
i. If none of the pixel value is 1, then assign this pixel a new label;
ii. If only one of this four pixels is 1, then assign its label to the current pixel;
iii. Then if more than 1 pixels are 1, then assign the minimal label to the current pixel, and make a note of equivalences for these pixels.
The second scan: merge the labels with the equivalent notes.
示例:
1. 源数据: