finding distance between centroids

9 次查看(过去 30 天)
mayfair
mayfair 2012-4-12
评论: emami.m 2019-3-11
Hi
I have a group of blobs of a binary image for which I have calculated the centroids.
I would like to find the distance between each of these centroids and then extract the two centroids which lie in a 40 to 45 range. I've seperated the X and Y cdts into 2 matrices like so:
>> X=centroids(:,1); Y=centroids(:,2); >> X
X =
121.3073
142.9425
168.1000
225.5856
522.9487
>> Y
Y =
207.2626
149.0276
114.7667
297.5586
299.9551
and then I tried computing the euclidean distance using pdist2 but I dont understand what it gives me and I dont see any 40s over here
D = pdist2(X,Y,'euclidean'); >> D
D =
85.9553 27.7203 6.5406 176.2513 178.6479
64.3200 6.0851 28.1759 154.6160 157.0126
39.1626 19.0724 53.3333 129.4586 131.8551
18.3230 76.5580 110.8189 71.9730 74.3695
315.6861 373.9211 408.1821 225.3902 222.9936
Any advice pls?

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2012-4-12
try
D = dist([X,Y]')
  7 个评论
Guillaume
Guillaume 2016-2-5
Even without the stats toolbox, you don't need a loop:
euclideandistance = hypot(bsxfun(@minus, X, X'), bsxfun(@minus, Y, Y'));
is all that's needed (assuming X and Y are vectors of the same size)
emami.m
emami.m 2019-3-11
Good job Guillaume,
It was a smart and exact solution.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by