finding interior or exterior points

조회 수: 4 (최근 30일)
Mohammad Golam Kibria
Mohammad Golam Kibria 2011년 6월 28일
Hi, I have a matrix as follows: I =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 1 1 0 0 1
0 0 0 0 1 0 1
0 0 0 1 0 1 1
0 0 0 0 0 0 0
L=bwlabel(I)
L =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 1 1 0 0 1
0 0 0 0 1 0 1
0 0 0 2 0 1 1
0 0 0 0 0 0 0
Here label 1 makes a continuous curve line. I need to know where point (5,4) belongs to, upper portion or lower portion. Thanks

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 6월 28일
Have matrix
I =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 1 0
0 0 1 0 0 1
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
1 0 0 0 1 0
0 1 0 0 1 0
0 0 1 0 1 0
0 0 1 0 1 0
0 0 1 0 1 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
We need to know where point (5,4) belongs to, upper portion or lower portion.
Variant of solution.
idx = {5,4};
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
if L(idx{:}) == L(1,1), disp('pixel in upper portions' );
elseif L(idx{:}) == L(end,1), disp('pixel in lower portions' );
else disp('pixel on boundaries of portions' );
end
L = bwlabel(~BW2,4);
if L(idx{:}) == max(L(1,:)), disp('pixel in upper portions' );
elseif L(idx{:}) == max(L(end,:)), disp('pixel in lower portions' );
else disp('pixel on boundaries of portions' );
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 6월 28일
The upper and lower portions are the same, as your curve of label 1 does not partition the space: you can go around by way of (3,1) to pass between "upper" and "lower" without encountering any "1".

카테고리

Help CenterFile Exchange에서 Propagation and Channel Models에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by