Finding Closed area in a region
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Akira Agata
el 11 de Nov. de 2019
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)
2 comentarios
Akira Agata
el 13 de Nov. de 2019
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
Ver también
Categorías
Más información sobre Elementary Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!