How to select, or filter, the external border/boundary in a set of (x,y)-points? [Part 2]
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, in a previous question, I asked about a method to obtain the external border from a set of points.
% Obtain coordinates corresponding to outside border by performing
% exclusive OR on the data, between "border b1" and "border b2":
z = setxor(b1,b2,'rows','stable');
to a larger dataset, that composes numerous "borders". The larger dataset is the following (here attached as well):
% load borders and plot them
load('borders2.mat','a')
figure; hold on
for i = 1 : length(a)
line(a{i}(:,1),a{i}(:,2),'color','k');
end
hold off
When I tried to use iteratively the method proposed by @Dyuman Joshi, I got a wrong output (and stuck) and I do not know how to solve the issue.. any idea or suggestion?
% remove iteratively "common edges", and plot the external common border
figure; hold on
b=a{1};
for i = 2 : length(a)
c=a{i};
b=setxor(b,c,'rows','stable');
plot(b(:,1),b(:,2),'r')
end
hold off
Note: as alternative method, I also tried to use the boundary function, with the maximum shrinking factor, but, still, it does not follow the exact shape of the external common border (as I would like).
2 Commenti
Dyuman Joshi
il 12 Lug 2023
The points that still appear on the inside (of outer boundary) are the points of intersection of 3 or more borders, which makes sense.
One approach would be to eliminate the intersection points (as mentioned below) before processing the data via for loop, but that seems difficult to implement.
I'll keep you updated if I find a solution.
load('borders2.mat','a')
figure
hold on
for i = 1 : length(a)
line(a{i}(:,1),a{i}(:,2),'color','k');
end
%a = cellfun(@(x) unique(x,'rows', 'stable'), a, 'uni', 0);
b=a{1};
for i = 2:numel(a)
c=a{i};
b=setxor(b,c,'rows','stable');
end
plot(b(:,1),b(:,2),'ro ','MarkerSize',5)
Risposta accettata
Bruno Luong
il 12 Lug 2023
Modificato: Bruno Luong
il 12 Lug 2023
load('borders2.mat')
n = length(a);
warning('off','MATLAB:polyshape:repairedBySimplify')
Q = polyshape(zeros(0,2));
for k=1:n
Q = union(polyshape(a{k}),Q);
end
plot(Q)
9 Commenti
Bruno Luong
il 12 Lug 2023
IMHO it requires quite a bit of programming and reflexion. Your attemps seem too quick to be effective.
Più risposte (1)
Kanishk Singhal
il 11 Lug 2023
If you plot after the loop,
figure; hold on
b=a{1};
for i = 2 : length(a)
c=a{i};
b=setxor(b,c,'rows','stable');
end
plot(b(:,1),b(:,2), '.')
hold off
you will get a plot like this.
Most boundary is removed but this the data is not perfect, some points which are inside are must be shared at unique to a cell.
Here you have two possibilities,
- Either clean the data remove these points or add these points in another cell.
- You get all the points from b, plot the points but make some kind of distance function which can identify these points.
In my opinion cleaning the data is a better option.
2 Commenti
Vedere anche
Categorie
Scopri di più su Delaunay Triangulation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!