finding interior or exterior points

3 ビュー (過去 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 件のコメント
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 28 日
Ok, thanks

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

その他の回答 (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 Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by