Extract segments of 1's from binary matrix

Hi,
I'm looking for a way to extract segments of 1's in a arbirtay big binary matrix. For example, in this matrix:
0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 1
0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 1
I would like to extract 3 segments automatically, for example like:
(2, 1:5)
(2:4, 8)
(3:4, 4) or alternativy (2:4,4)
I'm not bound to the above notation regarding start and stop, it can be stored in any way, it is just an example.
I have played around with find() but I don't seem to be able to get it right
/Niklas

 採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 5 日

0 投票

You can bwconncomp and pass in a connection array that is a central row or central column of 1s. You would do that twice, once for each direction, and ignore the components of size 1.

3 件のコメント

Niklas Persson
Niklas Persson 2022 年 7 月 5 日
Thank you!
The function looks promising, however, I'm not sure what you mean by:
pass in a connection array that is a central row or central column of 1s. You would do that twice, once for each direction, and ignore the components of size 1.
I have given the function a go with a 4 connectivty input, but it sounds very intresting if it is possible to do it for one dimension at the time, but I don't see that in the documentation for the function?
/Niklas
Niklas Persson
Niklas Persson 2022 年 7 月 5 日
Ah, I found it!
I should read the documentation more carefully
Thanks a lot!
Walter Roberson
Walter Roberson 2022 年 7 月 5 日
To expand a little, bwconncomp accepts connectivity that is a number, but it also accepts connectivity as a mask array such as [0 0 0;1 1 1;0 0 0]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by