How can I choose a subset of k points the farthest apart?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a set of n points.
Among these points, I wish to select the k points the "farthest apart" among the n points (in order to maximize the spatial representativity of the k points). And I want to try this with different values of k. (n is around 14, and I would then vary k for e.g. 2 to n in order to compare different cases)
Does any one has an idea about an efficient way to proceed?
(oh, and I am in a 2-D case)
2 Kommentare
Antworten (6)
Image Analyst
am 3 Jul. 2012
Bearbeitet: Image Analyst
am 3 Jul. 2012
Did you look at the convex hull? MATLAB has a function convhull(). The points farthest apart will be on the convex hull.
If you have more points that you want than are on the convex hull, you'll have to consider interior points. For example if you have 3 points on the vertex of the triangle and a cluster of points interior to them, the convex hull is the triangle. But if you want the 5 pairs that are farthest from each other, the convex hull can give you only 3 so to get the other 2 you need, you'd probably have to do an exhaustive search finding the distance of every point to every other point and then sort. Fortunately if you have only a handful of points like you do, then this should not take very long.
1 Kommentar
Thomas
am 3 Jul. 2012
BAsed on Image analysts answer and your clarifications
Peaks_Ref=[ 98 1547; % (x,y) position
641 1108 ; 124 476 ; 508 507 ; 619 512 ; 746 531 ; 342 507 ; 439 1018 ; 195 1099 ; 550 843; 721 1651; 384 1547; 305 2364 ; 175 1649 ; ];
plot(Peaks_Ref(:,1),Peaks_Ref(:,2),'Marker','x','LineStyle','none')
out=convhull(Peaks_Ref);
extremes=Peaks_Ref(out,:);
hold on
plot(extremes(:,1),extremes(:,2),'Marker','o','LineStyle','none','Color','g','MarkerSize',6,'MarkerFaceColor',[0 0.498039215803146 0])
Dr. Seis
am 3 Jul. 2012
Bearbeitet: Dr. Seis
am 3 Jul. 2012
Went with a "simple" way - tried to maximize the sum of the distances between each point in the sub-set of "n" below (similar to way you described earlier):
n = randn(14,2);
k = 7;
b = nchoosek(1:length(n),k);
c = zeros(size(b,1),1);
for i = 1 : size(b,1)
subb = b(i,:);
subn = n(subb,:);
for j = 1 : size(b,2)-1
for k = j+1 : size(b,2)
c(i) = c(i) + sqrt((subn(j,1)-subn(k,1))^2 + ...
(subn(j,2)-subn(k,2))^2);
end
end
end
[d,e] = max(c);
f = b(e,:);
%figure
plot(n(:,1),n(:,2),'bo',n(f,1),n(f,2),'rx');
legend('Point Set',sprintf('"Best" %d Points',k));
0 Kommentare
Dr. Seis
am 5 Jul. 2012
Bearbeitet: Dr. Seis
am 5 Jul. 2012
Added a few more tests (including your latest) and added your data (instead of just random dataset), which may be of interest. Relevant code:
n = [ 98 1547; 641 1108 ; 124 476 ; 508 507 ; 619 512 ; 746 531 ; 342 507 ; 439 1018 ; 195 1099 ; 550 843; 721 1651; 384 1547; 305 2364 ; 175 1649]
k = 7;
b = nchoosek(1:length(n),k);
c1 = zeros(size(b,1),1);
c2 = zeros(size(b,1),1);
c3 = zeros(size(b,1),1);
c4 = zeros(size(b,1),1);
c5 = zeros(size(b,1),1);
for i = 1 : size(b,1)
subb = b(i,:);
subn = n(subb,:);
subd = delaunay(subn(:,1),subn(:,2));
% Method 1 (Sum of distances between each pair in points sub-set)
for j = 1 : size(b,2)-1
for k = j+1 : size(b,2)
c1(i) = c1(i) + sqrt((subn(j,1)-subn(k,1))^2 + ...
(subn(j,2)-subn(k,2))^2);
end
end
% Method 2 (Sum of Delaunay triangle perimeter, squared)
for j = 1 : size(subd,1)
c2(i) = c2(i) + ...
( sqrt((subn(subd(j,1),1)-subn(subd(j,2),1))^2 ...
+ (subn(subd(j,1),2)-subn(subd(j,2),2))^2) ...
+ sqrt((subn(subd(j,3),1)-subn(subd(j,2),1))^2 ...
+ (subn(subd(j,3),2)-subn(subd(j,2),2))^2) ...
+ sqrt((subn(subd(j,1),1)-subn(subd(j,3),1))^2 ...
+ (subn(subd(j,1),2)-subn(subd(j,3),2))^2) )^2;
end
% Method 3 (Sum of Delaunay triangle area)
for j = 1 : size(subd,1)
c3(i) = c3(i) + polyarea(subn(subd(j,:),1),subn(subd(j,:),2));
end
% Method 5 (Delaunay + Convhull)
for ka=1:size(subd,1)
for k2=1:3
c5(i)= c5(i) + ...
sqrt(((subn(subd(ka,k2),1)-subn(subd(ka,mod(k2,3)+1),1))^2)+...
((subn(subd(ka,k2),2)-subn(subd(ka,mod(k2,3)+1),2))^2));
end
end
CVHL=convhull(subn(:,1),subn(:,2));
for kx=1:length(CVHL)-1
c5(i)=c5(i) + ...
sqrt(((subn(CVHL(kx),1)-subn(CVHL(kx+1),1))^2)+...
((subn(CVHL(kx),2)-subn(CVHL(kx+1),2))^2));
end
end
% Method 4 (Method 2 and Method 3)
c4 = c2/max(c2) + c3/max(c3);
[~,e1] = max(c1);
[~,e2] = max(c2);
[~,e3] = max(c3);
[~,e4] = max(c4);
[~,e5] = max(c5);
f1 = b(e1,:);
f2 = b(e2,:);
f3 = b(e3,:);
f4 = b(e4,:);
f5 = b(e5,:);
figure;
subplot(2,3,1);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15);
title('Starting Point Set'); axis equal;
subplot(2,3,2);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f1,1),n(f1,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-1)',k)); axis equal;
subplot(2,3,3);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f2,1),n(f2,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-2)',k)); axis equal;
subplot(2,3,4);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f3,1),n(f3,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-3)',k)); axis equal;
subplot(2,3,5);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f4,1),n(f4,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-4)',k)); axis equal;
subplot(2,3,6);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f5,1),n(f5,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-5)',k)); axis equal;
2 Kommentare
Siehe auch
Kategorien
Mehr zu Delaunay Triangulation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!