Fast way to 2D data thinning

Hi,
I have a set of 2D data in the format [X Y] and am going to thin them based on a certain distance threshold,i.e. if points are very close less than a threshold, one is eliminated. This process continues until the distance between any two points is bigger than the threshold. I developed a code to do that but it is very time consuming. I am wondering if there is a better way of doing this in Matlab.
Thank you.
Mehdi

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2015 年 7 月 17 日
編集済み: Andrei Bobrov 2015 年 7 月 17 日

0 投票

X = randi([5,100],20,1);
Y = randi([-100,10],20,1);
trld = 10; % threshold
n = numel(X);
ii = nchoosek(1:n,2);
a = hypot(X(ii(:,1))-X(ii(:,2)),Y(ii(:,1))-Y(ii(:,2)));
lo = a > trld;
ind = unique(ii(lo,:));
out = [X(ind),Y(ind)];

1 件のコメント

Mehdi Ravanbakhsh
Mehdi Ravanbakhsh 2015 年 7 月 17 日
Thanks Andrei. I tested your code and it never goes beyond nchoosek(1:n,2); Why it is so? nchoosek seems to be computationally heavy.
I test my own code which takes 3 minutes for 150000 points but your code goes forever. Any advice?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeJust for fun についてさらに検索

質問済み:

2015 年 7 月 17 日

コメント済み:

2015 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by