how to find mid point between two centroids of objects?

hello friends,
I want to find mid points between two centroids of objects.
I have used this code :
for n=1:Ne
[r,c] = find(L==n);
s = regionprops(L, 'centroid');
centroids = cat(1, s.Centroid);
imshow(image);
hold on
plot(centroids(:,1), centroids(:,2), 'b*');
I found the result as
This code gives the centroids from the corner points too. which are unnecessary. how to remove them?
I would be thankful if someone helps me to find mid point between two two centroids of objects by finding the distance between them or else.
thanks in advance.

 Accepted Answer

mean(centroids)

6 Comments

Dear Walter Roberson,
I tried this code by
mid= mean(centroids); plot(mid(:,1),'r*');
And result is:
I think it is not provide accurate mid point :(
plot(mid,'r*')
Remember, the first column is the x only.
thank you walter roberson, but it gives the same result with two points instead of one.
Sorry should be
plot(mid(1), mid(2), 'r*')
its working...thank you so much...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!