finding adjacent value in a matrix
1 view (last 30 days)
Show older comments
Hi, I have a portion of a matrix as follows:
I =
0 1 0 0 1 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
I know the position of two 1s i.e (6,1) and (6,6). I need to know whether this two 1s are connected and if connected the positions of all 1s from first 1 to last 1. connected means any of eight neighbor of 1st 1 has 1,any of eight neighbor of 1st 1's neighbor has value 1 and it ends at 1 at (6,6) Here (1,2) and (1,5) is not connected but (6,1) and (6,6) are connected
0 Comments
Accepted Answer
Walter Roberson
on 14 Jun 2011
bwlabel() and then regionprops . If the labels differ for the two positions then they are not connected; if they are connected, then the pixel list from regionprops will show the path, provided there are no "spurs".
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!