0
votes

I researched a bit about connected components. In either MATLAB or the OpenCV library, they always indicate that the kernel can be a 3x3 array and it can be either 4-connected or 8-connected. I did quite a bit of research but am unable to find an answer.

I know that a kernel can be in any shape. But in the connected components case, say, we have a 5x5 kernel, it can detect 1s even if they are in another label. (Due to size, 5x5 kernel can see 2 pixel area from anchor). And, say, we have 4x4 kernel (even sized kernel), in this case we don't even have an anchor. So my question is how can I apply connected component labeling with 4x4 and 5x5 kernels?

1
Sorry if I am being vague. About connected component labeling, I was asked to do three different labeling, with 3x3,4x4 and 5x5 full 2D array kernels. 3x3 is simple, 5x5 is kinda vague for me but I can guess it is not optimal for things I mentioned above. My biggest dilemma is how to done CC analysis with 4x4 array. I was asking if there is a way, since there is no "middle point" in structural element, in this case 4x4. I dont know how to apply or if one can apply even-structered kernell to the image in CCAMasmm
Ok, I’ve edited your post to match what I think you mean to say. Please edit further if I misunderstood.Cris Luengo
You can choose the anchor to be anywhere you want in the kernel. Often, for a mxn kernel, the chosen anchor is ceil([m/2, n/2]) (using 1-based indexing).beaker

1 Answers

3
votes

Indeed, Connected Component Analysis (CCA) is usually applied with a 3x3 kernel, or rather, applied taking only the direct 4 or 8-connected neighbors as neighbors.

But one can choose larger neighborhoods to be considered connected. With a 5x5 kernel, gaps of one pixel in size can be ignored, making larger connected components.

To implement CCA with a larger kernel, one can apply a dilation to the image, apply a normal CCA, and then reset back to 0 those pixels that were 0 in the input image. The dilation should be of such a size that the desired gap size is filled. For the 5x5 kernel case, which ignores gaps of 1 pixel, we need to apply a 2x2 dilation to fill 1-pixel gaps.

Regarding the even-sized kernels: In general, such kernels have no problem. One can define the origin (anchor) anywhere one wishes. We always end up with an asymmetric kernel.

However, with CCA, it is unclear to me what the meaning would be of an asymmetric kernel. The neighbor two pixels to the right is connected, but the one two pixels to the left is not. This pixel B is connected to A, but A is not connected to B? Doesn’t seem to make sense to me. A connection definition must be symmetric to make sense. This is similar to the definition of a distance, which requires that distance(a,b)=distance(b,a).