how to get outline of multiple shapes

조회 수: 10 (최근 30일)
Asliddin Komilov
Asliddin Komilov 2023년 12월 18일
답변: Asliddin Komilov 2024년 1월 4일
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 2023년 12월 19일
I need a shape, x and y axis.

댓글을 달려면 로그인하십시오.

채택된 답변

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 Object Programming에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by