MATLAB: Finding interior or exterior points

pointposition;

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

Best Answer

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