フィルターのクリア

eliminating isolated areas in a matrix

1 回表示 (過去 30 日間)
Andrew Luce
Andrew Luce 2022 年 4 月 20 日
編集済み: Matt J 2022 年 4 月 20 日
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

回答 (1 件)

Matt J
Matt J 2022 年 4 月 20 日
編集済み: Matt J 2022 年 4 月 20 日
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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by