필터 지우기
필터 지우기

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 CenterFile Exchange에서 Hilbert 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