finding interior or exterior points

3 次查看(过去 30 天)
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 中查找有关 Random Number Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by