how to fill the interior of a closed surface?

19 ビュー (過去 30 日間)
M.S. Khan
M.S. Khan 2021 年 2 月 5 日
コメント済み: Star Strider 2021 年 2 月 7 日
hi dear community members,
please guide me, i have a closed boundary surface. i want to fill the interior.
i am using for loop but i could not succeed.
regards

採用された回答

Star Strider
Star Strider 2021 年 2 月 5 日
編集済み: Star Strider 2021 年 2 月 5 日
Try this:
D = readmatrix('Boundary_closed_1s_3s.txt');
figure
[c,h] = contour(D, [1 1]*0.5);
Levels = h.LevelList;
idx = find(c(1,:) == Levels(1));
Len = c(2,idx);
for k = 1:numel(idx)
x{k} = c(1,idx+1:Len(k));
y{k} = c(2,idx+1:Len(k));
end
[b,v] = boundary(x{1}(:), y{1}(:)); % Introduced In R2014b
figure
fill(x{1}(b), y{1}(b), 'r')
title('Boundary')
figure
fill(x{1}, y{1}, 'g')
title('Filled Contour')
It uses the contour function to extract the outlines of the triangle, then first boundary (R2014b and later) to fill the triangle, and then a second one to fill the contour. Choose the one you want.
For figure(1):
.
EDIT — (5 Feb 2021 at 03:06)
The ‘v’ output of boundary is the area it encloses. I assume it corresponds to pixels, however I cannot determine that. Nothing in the original Question mentioned anything about pixels. It might be possible to use ‘x{1}(b)’ and ‘y{1}(b)’ with the original data to outline tha area in the image. The ‘y’ axis direction in the image will be reversed from the plot direction.
  8 件のコメント
M.S. Khan
M.S. Khan 2021 年 2 月 7 日
Thanks Star Strider. Regards.
Star Strider
Star Strider 2021 年 2 月 7 日
As always, my pleasure!

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

その他の回答 (1 件)

David Hill
David Hill 2021 年 2 月 5 日
編集済み: David Hill 2021 年 2 月 5 日
Look at polyshape() (assuming your have the coordinates of your surface)
pgon = polyshape([0 0 1 3], [0 3 3 0]);
a=plot(pgon);
a.FaceColor=[0 1 0];
  3 件のコメント
David Hill
David Hill 2021 年 2 月 5 日
Look at the documentation. Polyshape can handle irregular shapes but the coordinates need to be in order.
doc polyshape
Don't understand your pixel question.
M.S. Khan
M.S. Khan 2021 年 2 月 5 日
Dear David, i mean, using a.FaceColor=[0 1 0]; we got a colored polygon. can we count how many pixels were used in colored area.

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

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by