Joining label

1 回表示 (過去 30 日間)
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 19 日
Hi I have the following matrix
I =
0 1 0 0 1 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
and
L=bwlabel(I)
L =
0 2 0 0 3 0
0 0 0 3 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
I need to join or merge those label who have minimum distance 2. Is there any one to help?
  1 件のコメント
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 20 日
label 1 and label 3 are in minimum distance 2 but label 2 is not within minimum distance 2 with any of label 1 or 3.
the out put might be like bellow:
0 2 0 0 1 0
0 0 0 1 0 0
0 0 0 1 0 0
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1

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

回答 (3 件)

Jan
Jan 2011 年 6 月 19 日
To join the regions, exapand them at first. I assume "minimum distance of 2" means a dilation with a 3x3 matrix:
I = [0 1 0 0 1 0; ...
0 0 0 1 0 0; ...
0 0 0 0 0 0; ...
0 0 1 1 0 0; ...
0 1 0 0 1 0; ...
1 0 0 0 0 1];
I2 = imdilate(I, ones(3, 3));
L = bwlabel(I2);
% Now remove all points, which are 0 in the original matrix:
L(I == 0) = 0;

the cyclist
the cyclist 2011 年 6 月 19 日
It is not clear to me what you mean by "join or merge". Perhaps you can tell us what the correct output is for the example you have given?
The find() command might be part of what you need. For example,
>> [i,j] = find(L>=2);
will give you the (i,j) coordinates of the values of L greater than or equal to 2.

Andrei Bobrov
Andrei Bobrov 2011 年 6 月 19 日
C = nchoosek(1:max(L(:)),2);
[ii jj c] = arrayfun(@(i1)find(bwdist(L==C(i1,1)).*(L==C(i1,2))),1:size(C,1),'un',0);
leq = C(cellfun(@(x)min(x),c)<=2,:);
for jj = 1:size(leq,1),
leq(ismember(leq(:,1),leq(jj,2)),1) = leq(jj,1);
L(L==leq(jj,2)) = leq(jj,1);
end
CORRECTED
I1 = I;
L = bwlabel(I1);
for ii = max(L(:)):-1:1
c{ii} = bwdist(L==ii)==1;
end
I1(sum(cat(3,c{:}),3) > 1)=1
Lnew = bwlabel(I1)

カテゴリ

Help Center および File ExchangeHilbert and Walsh-Hadamard Transforms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by