Connected component labeling

来源:互联网 发布:java interface 属性 编辑:程序博客网 时间:2024/06/08 14:17

以 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. 源数据:

Screenshot-Pixel Region (Figure 1).png

2. First scan之后

Screenshot-Pixel Region (Figure 2).png

Equivalence table:

Set IDEquivalent Labels11,221,233,4,5,6,743,4,5,6,753,4,5,6,763,4,5,6,773,4,5,6,73. According to the equivalence table, second scan 之后:

Screenshot-Pixel Region (Figure 3).png