how to get outline of multiple shapes

3 vues (au cours des 30 derniers jours)
Asliddin Komilov
Asliddin Komilov le 18 Déc 2023
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 commentaires
Image Analyst
Image Analyst le 18 Déc 2023
Do you require them to be shape objects or can the answer be a digital image?
Asliddin Komilov
Asliddin Komilov le 19 Déc 2023
I need a shape, x and y axis.

Connectez-vous pour commenter.

Réponse acceptée

Asliddin Komilov
Asliddin Komilov le 4 Jan 2024
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');

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 19 Déc 2023
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 commentaires
Asliddin Komilov
Asliddin Komilov le 19 Déc 2023
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 le 22 Déc 2023
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)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by