Finding Closed area in a region

21 次查看(过去 30 天)
Armin Mashhadi
Armin Mashhadi 2019-11-10
评论: Akira Agata 2019-11-13
Hi,
Fisrt of all thanks for your helping.
As a part of my thesis, I need to find all closed area in a set of data. For example as you see in the picture there is just one closed area. (Data has been attached)
I need to find JUST closed area. I tried to use polygen command, but it will connect first and last points, so will create several which causes wrong areas and wrong answers. (here says there are 3 closed area)
Do you have any Idea how can i handle it?

回答(1 个)

Akira Agata
Akira Agata 2019-11-11
By using polyshape, simplify and regions functions, you can obtain polyshape object for each closed area. The following is an example:
load('Data.mat');
pgonAll = polyshape(Data(:,1),Data(:,2),'Simplify',false);
pgonAll = simplify(pgonAll);
pgonEach = regions(pgonAll);
figure
plot(Data(:,1),Data(:,2))
hold on
plot(pgonEach(2))
legend({'Data','pgonEach(2)'},'FontSize',12)
pgon.png
  2 个评论
Armin Mashhadi
Armin Mashhadi 2019-11-12
Hi again.
Thank you a lot, but i don't think that workdes for me.
Using polygon, you turned "simplify" off, then use it again with "simplify" command (Why?). So you re-creat the regions and choosed the close one manually.
My problem is that how to choose JUST closed areas. not to find them all and see whitch one is closed.
I think i had not describe my problem well, sorry about that.
Akira Agata
Akira Agata 2019-11-13
Hi Armin-san,
Thank you for your response.
>Using polygon, you turned "simplify" off, then use it again with "simplify" command (Why?).
This is because, in your case, polyshape function returns warning message when turning "simplify" on. So I separated each step. (Just in case, please note that this warning message is only for "warning". The output becomes the same)
>My problem is that how to choose JUST closed areas.
OK.
Using the fact that the vertices does NOT jump suddenly for closed area(s), you can extract these polyshape(s). The following is one example. I hope this will help you somehow!
load('Data.mat');
pgonAll = polyshape(Data(:,1),Data(:,2),'Simplify',false);
pgonAll = simplify(pgonAll);
pgonEach = regions(pgonAll);
% Find polyshape(s) whose neighbouring vertices doesn't "jump"
% (e.g distance > 1)
idx = false(size(pgonEach));
for kk = 1:numel(pgonEach)
v = pgonEach(kk).Vertices;
d = vecnorm(diff(v),2,2);
if all(d < 1)
idx(kk) = true;
end
end
% Extract target polyshape(s)
pgonEach = pgonEach(idx);
% Visualize
figure
plot(Data(:,1),Data(:,2))
hold on
if ~isempty(pgonEach)
for kk = 1:numel(pgonEach)
plot(pgonEach(kk))
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by