How to judge a point whether inside a closed contour or not?

9 ビュー (過去 30 日間)
John W. Z
John W. Z 2016 年 3 月 21 日
コメント済み: John W. Z 2016 年 3 月 22 日
Assume a circle contour image matrix
c= [ 0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0 ]
and a point p=[4 3], apparently inside this circle. But, how to make such judgement in matlab.

採用された回答

Walter Roberson
Walter Roberson 2016 年 3 月 21 日
http://www.mathworks.com/help/images/ref/imfill.html imfill ('holes'). If the point gets assigned a non-zero value then it is inside a closed contour.
  2 件のコメント
Image Analyst
Image Analyst 2016 年 3 月 22 日
Clever. If you want to know if it's on the perimeter or inside (not on perimeter) then check c first
if c(4,3)
% On perimeter.
else
filledc = imfill(c, 'holes');
if filledc(4,3)
% Inside, not on perimeter
else
% Not inside any closed contour at all
end
end
If you don't care whether it's on the perimeter or inside, just do
filledc = imfill(c, 'holes');
if filledc(4,3)
% Inside, or on perimeter
else
% Not inside any closed contour at all
end
John W. Z
John W. Z 2016 年 3 月 22 日
Cheers~

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by