eliminating isolated areas in a matrix
1 view (last 30 days)
Show older comments
I have four 4x4 matrices that I want to concatinate together to make 1 8x8 that will contain 1's and 0's. How can I check to see if when I combine the 4 together that I do not create areas that are "isolated". In other words sections of 1's that are not connected to the rest of the 1's. Connecitons would be if a 1 has another 1 above, below, to the right or to the left.
I can some challenge with the edges of the matrix and if there are any peninusla type regions.
thank you
Andrew
1 1 0 0 1 1 1 1 %failure due to island formed here % Both of these should be able to pass (i just rotated some of the sections)
1 0 0 1 0 1 1 1 1 1 0 0 1 1 1 1 <-- 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1
1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 0 1 1
1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1
--> 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 Comments
Answers (1)
Matt J
on 20 Apr 2022
Edited: Matt J
on 20 Apr 2022
How can I check to see if when I combine the 4 together that I do not create areas that are "isolated"
Use bwconncomp to count the number of connected regions. If they are greater than 1, you know you will have created what you don't want.
BW=[1 1 0 0 1 1 1 1
1 0 0 1 0 1 1 1
1 1 1 1 0 0 1 0
1 1 1 1 0 0 0 0
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1];
CC=bwconncomp(BW,4);
failure = (CC.NumObjects>1)
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!