finding region

8 ビュー (過去 30 日間)
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 29 日
Hi I have a matrix as follows:
I=
1 1 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Here 1 has divided the matrix in two parts I need to have the indices of these two separate parts. say idx1 will be upper zeros and idx2 contains lower zero indices.Can any one help.

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 6 月 29 日
BW2 = bwmorph(I,'diag');
L = bwlabel(~BW2);
Id1 = bwdist(I,'chessboard') == 1;
for i1 = 1:max(L(:))
L(bwdist(L == i1,'chessboard')==1 & Id1) = i1;
end
idx1 = find(max(L(1,:))==L);
idx2 = find(max(L(end,:))==L);
EDIT as at Sean
L = bwlabel(~I,4);
idx1 = find(max(L(1,:))==L);
idx2 = find(max(L(end,:))==L);
  1 件のコメント
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 30 日
Thanks

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

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 6 月 29 日
CC = bwconncomp(~I,4);
CC.PixelIdxList will contain the linear indices. To get the sub indices either use regionprops with the 'pixellist' option or ind2sub
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 6 月 29 日
+1
Hi Sean! I stupid, forgotten about the variable 4-connectivity. Thanks

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


Paulo Silva
Paulo Silva 2011 年 6 月 29 日
Just for fun
I=[1 1 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0];
up=[];down=[];
for c=1:size(I,2)
d=0;u=1;
for r=1:size(I,1)
if(d==1)
down=[down sub2ind(size(I),r,c)];
end
if(I(r,c)==1)
d=1;u=0;
end
if u==1
up=[up sub2ind(size(I),r,c)];
end
end
end
disp('index of zeros bellow the 1')
down
disp('index of zeros above the 1')
up
%for big arrays it's better to pre-allocate the up and down vectors, much faster
  1 件のコメント
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 30 日
Thanks. Its also ok.How to pre-allocate the up and down vectors?

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by