Clear Filters
Clear Filters

how to get outline of multiple shapes

7 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 18 Dec 2023
Do you require them to be shape objects or can the answer be a digital image?

Sign in to comment.

Accepted Answer

Asliddin Komilov
Asliddin Komilov on 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');

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Dec 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 Comments
Asliddin Komilov
Asliddin Komilov on 19 Dec 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 on 22 Dec 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)

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!