Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

Last week I wrote about a user's request to perform connected-component labeling with an unusual connectivity definition:

[1 0 1 0 1]

This definition, which is not supported by Image Processing Toolbox functions, has the effect of dividing an image into two
noninteracting subimages, one containing the even columns and one containing the odd columns.

That description gives us our needed clue about how to implement such a thing. We split the image up into the two subimages,
find the connected components in each subimage, and then merge the results.

Now the pixel index lists for each connected component have been corrected to refer to pixel locations in the original image.
Next we make a new connected component struct containing both sets of components.

3 CommentsOldest to Newest

Hi Steve.
Thanks for the solution. However, while your method works for the particular neighbourhood I gave, I was expressing a more general problem which this approach doesn’t solve. Consider nhood = [0 0 0 0 1; 0 1 0 0 0; 0 1 1 1 0; 0 0 0 1 0; 1 0 0 0 0]. Interestingly, the code to find connected components given such an arbitrary nhood already comes with MATLAB. Using the private function bwlabelnmex, I can do:
A = bwlabelnmex(rand(100) < 0.1, nhood);
and I believe I get the right answer, at least for this example. I think it’s a shame that this functionality isn’t (easily) available to the user. I acknowledge that it’s rare that people need to do this sort of thing, but it has cropped up for me when dealing with sparsely connected cliques in MRFs over images. Such cliques occur in algorithms such as the one presented here:http://cns.bu.edu/~lgrady/cremers2006learning_final.pdf
Oliver

@Oliver: Thanks for your tip! I have arrays where I’d like to run bwlabel on columns only (i.e. with a neighborhood of ones(3,1), since the array contains different realizations of a process and I need a good way to identify runs of ones.

These postings are the author's and don't necessarily represent the opinions of MathWorks.