I have 8 balloons which scatter on a binary image with no specific pattern, I want to get the distance every pairwise of balloons, could you give me any suggestion or codes?how can I do that?

1 view (last 30 days)
I have 8 balloons which scatter on a binary image with no specific pattern, I want to get the distance between every pairwise of balloons, could you give me any suggestion or codes?how cando i that?

Accepted Answer

Image Analyst
Image Analyst on 27 May 2014
Edited: Image Analyst on 27 May 2014
See my image segmentation tutorial to get the centroids. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Then use the Pythagorean theorem to find distances between each pair of centroids. Post your image if you want better advice.
  3 Comments
Image Analyst
Image Analyst on 27 May 2014
Let me attach the BlobsDemo tutorial I referred you to. To find the centroid of any given blob, you can do
blobCentroid = blobMeasurements(k).Centroid;
So you just do a double loop:
for j = 1 : numberOfBlobs % Loop through all blobs.
for k = 1 : numberOfBlobs % Loop through all blobs.
blobCentroidj = blobMeasurements(j).Centroid;
blobCentroidk = blobMeasurements(k).Centroid;
horizontalDistances(j, k) = blobCentroidj(1) - blobCentroidk(1);
verticalDistances(j, k) = blobCentroidj(2) - blobCentroidk(2);
end
end
Then just plug in any j and k you want and get the horizontal or vertical distances.

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!