MATLAB: Calculating the distances of the centers of objects to each other at image

digital image processingimage analysisimage processingImage Processing Toolboximage segmentationStatistics and Machine Learning Toolbox

Hi everyone I am working on image processing project.There is an image who has circular roi (region of interest) and there is a two object at the circular roi.I want to calculate distances of the centers of objects each other and i wanna find the center points of circular area.How can i do this?Can someone give me tips about it?Thank you already.

Best Answer

If you have the Statistics and Machine Learning Toolbox, use pdist2
props = regionprops(binaryImage, 'Centroid');
centroids = [props.Centroid];
xCentroids = centroids(1:2:end);
yCentroids = centroids(2:2:end);
xy = [xCentroids, yCentroids];
distances = pdist2(xy, xy)