eliminating isolated areas in a matrix

1 vue (au cours des 30 derniers jours)
Andrew Luce
Andrew Luce le 20 Avr 2022
Modifié(e) : Matt J le 20 Avr 2022
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

Réponses (1)

Matt J
Matt J le 20 Avr 2022
Modifié(e) : Matt J le 20 Avr 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)
failure = logical
1

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by