Find continuous elements in matrix

8 ビュー (過去 30 日間)
Fabio
Fabio 2012 年 6 月 18 日
Hi everyone,
my problem is the following: i've one matrix made of two possible values (i.e. 1 and 0). I also have the coordinates of one "starting point". I would like to select all the ones that are connected to this point without selecting the ones that are separeted by zeros. I can't figure out a way to solve the problem... can you help me?
Thanks in advance, Fabio
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 18 日
Do you have the Image Processing Toolbox?

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 18 日
use functions bwlabel and regionprops from Image Processing Toolbox
eg
youridx = {10,6}; % coordinates of one "starting point" (row - 10, column - 6)
a = [...
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 1 0
0 0 1 0 1 0 0 1 0 0
0 1 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0 0
0 0 0 0 1 1 1 0 0 0];
S = regionprops(a~=0,'PixelList');
t = bwlabel(a);
out = = fliplr(S(t(idx{:})).PixelList);
  2 件のコメント
Fabio
Fabio 2012 年 6 月 19 日
Thank you very much, this is working very well! I didn't mention in my introduction that the matrix i'm looking at is a 3d matrix (or it could be in future applications a n-dimension matrix, with n>3), but hopefully i'll find a way to extend this code to the 3rd dimension. If you have any other suggestion please tell me.
Sean de Wolski
Sean de Wolski 2012 年 6 月 19 日
should be extendable as is.

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 6 月 18 日
CC = bwconncomp(a);
CC.PixelIdxList{:}

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by