I want to implement Connected-Component Labeling but I'm not sure if I should do it in a 4-connected manner or 8-connected. I've read about 3 materials on it but none of them explains their choice of graph connectivity. One of them chose 8, the other two 4 and one of those two said that he chose 4 for a shorter program trace (noting that extending his pseudocode to 8 should be trivial)开发者_运维知识库. So, what are the merits of one over the other?
The only real difference is how the algoritms handle diagonal configurations. With a diamond neighborhood, diagonal "in" elements wirll not be connected. With the square neighborhood they will.
You might want to treat this as an ambiguous case instead of just alwys doing one or the other. Some existing strategies will look at the actual values before binarisation and interpolate a value between the diagonal elements. This value is binarized and when it too is in, the diagonal elements are connected. Otherwise, they are not.
Well, based on my humble experience, I would say there's no 'merit' in using 4 or 8 connected.
What will happen is that using 4 connected for labelling, you will probably get more objects.
It's like an island of pixels. Some 'islands' are connected with others islands by only one pixel, and if this pixel is in diagonal, using 4 connected will label both islands as two separate objects, while 8 connected will assume they are only one object.
I regret to dissent with this page's comments, at least in what concerns search algorithms in binary images. In there clear advantages can be shown when using 4- over the the 8-connectivity. That is, in the geometry of the solution. Obviously, the disadvantages are in the time complexity (theoretically operating in "4-mode" has a time complexity twice as large as in the other mode).
精彩评论