Assume I have the following binary image
BW = [ 1 0 0 0; 0 0 0 0; 0 1 1 0; 0 0 0 0; 0 0 0 0 0 1 1 0 ];
I would like to find all connected components in this binary image, where 2 points are connected if they are at most 2 rows and at most 1 column away from each other and both have the value 1. The function bwlabeln seems to be useful for this task, but it does not provide me the flexibility of specifying the desired pixel connectivity. My problem statement seems to translate to a 5-by-3 pixel connectivity of all ones. Is there any function that can help me here?
The desired labeling of connected components is
L = [ 1 0 0 0; 0 0 0 0; 0 1 1 0; 0 0 0 0; 0 0 0 0 0 2 2 0 ];
and the number of connected components is 2.
Best Answer