how to get outline of multiple shapes

3 次查看(过去 30 天)
Hi,
I have asked about it before
but the answer did not fit all my data, so I need help on this one too.
I have multiple shapes I need to merge into a single shape, because I have sets of shapes those I have to merge and compare with each other (put into a one plot). the set of data is attached and I can plot it like this:
plot(X(:, [1:end 1])', Y(:, [1:end 1])')
let me know, if you know how to do it, thanks.
  2 个评论
Image Analyst
Image Analyst 2023-12-18
Do you require them to be shape objects or can the answer be a digital image?

请先登录,再进行评论。

采纳的回答

Asliddin Komilov
Asliddin Komilov 2024-1-4
This is the final version:
cutxr=X(1:size(X)/2,:);
cutyr=Y(1:size(Y)/2,:);
cutxl=X(size(cutxr):end,:);
cutyl=Y(size(cutyr):end,:);
% plot(cutxl(:, [1:end 1])', cutyl(:, [1:end 1])'); hold on
% plot(cutxr(:, [1:end 1])', cutyr(:, [1:end 1])')
% find convex hull, use 0 for s
Kr = boundary(double(cutxr(:)),double(cutyr(:)),0);
Kl = boundary(double(cutxl(:)),double(cutyl(:)),0);
Xhr = cutxr(Kr);
Yhr = cutyr(Kr);
Xhl = cutxl(Kl);
Yhl = cutyl(Kl);
% figure
% plot(Xhr,Yhr); hold on
% plot(Xhl,Yhl)
% create shapes to get the whole figure
shapeL=polyshape(Xhl,Yhl, 'simplify', false);
shapeR=polyshape(Xhr,Yhr, 'simplify', false);
shapeRL=[shapeL shapeR];
shape=union(shapeRL);
[xxx, yyy]=boundary(shape);
% figure
% plot(xxx,yyy);
%reshape into same index length to avoid output error
XY=linspace(1, length(xxx),1000);
hullX=interp1(1:1:length(xxx),xxx,XY,'linear');
hullY=interp1(1:1:length(xxx),yyy,XY,'linear');

更多回答(1 个)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023-12-19
Maybe you want to get something like this shape, e.g.:
load('Data.mat')
for ii=1:height(X)
PGON = polyshape(X(ii,:),Y(ii,:),'Simplify',true);
plot(PGON)
hold on
end
Warning: Boundaries with fewer than 3 points were removed.
Warning: Boundaries with fewer than 3 points were removed.
Warning: Boundaries with fewer than 3 points were removed.
Warning: Boundaries with fewer than 3 points were removed.
Warning: Boundaries with fewer than 3 points were removed.
xlim([-3 3])
ylim([0, 0.2])
  2 个评论
Asliddin Komilov
Asliddin Komilov 2023-12-19
I need one shape that is from outline of all shapes and for my set of data it will look like a big letter "V".
Asliddin Komilov
Asliddin Komilov 2023-12-22
I think it will work if the 2 halves of the data are treated separately as follows, but I don't know how to join them together and get read of common point.
cutxr=X(1:size(X)/2,:);
cutyr=Y(1:size(Y)/2,:);
cutxl=X(size(X)/2:end,:);
cutyl=Y(size(Y)/2:end,:);
% plot(cutxl(:, [1:end 1])', cutyl(:, [1:end 1])'); hold on
% plot(cutxr(:, [1:end 1])', cutyr(:, [1:end 1])')
% find convex hull
Kr = boundary(double(cutxr(:)),double(cutyr(:)),1);
Kl = boundary(double(cutxl(:)),double(cutyl(:)),1);
Xhr = cutxr(Kr);
Yhr = cutyr(Kr);
Xhl = cutxl(Kl);
Yhl = cutyl(Kl);
% plot the convex hull, show the curve endpoint
plot(Xhr,Yhr); hold on
plot(Xhl,Yhl)

请先登录,再进行评论。

类别

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

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by