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 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2014-5-27
编辑:Image Analyst 2014-5-27
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 个评论
Image Analyst
Image Analyst 2014-5-27
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by