Distances between regions in matlab
1 view (last 30 days)
Show older comments
I am trying to find the distance between two points for different regions. However in order to get from one region to another there is a given point on the boundary between the two regions where you would go from point 1 to the boundary point to point 2. My problem is there are 8 different regions. So if point 1 is in region 1 and point 2 is in region 8 I may have to find the distance between point 1 to boundary point 1 to boundary point 2 etc. to point 8. The explanation here may be bad but I thought id give it a shot.
0 Comments
Answers (1)
Image Analyst
on 1 Jul 2013
Why don't you just go between the centroids of the regions?
There are other definitions of distances. It sounds like you'd better take a look at the Hausdorf distance to see if that's what you need: http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/98/normand/main.html
2 Comments
Image Analyst
on 22 Jan 2022
@Zaid B, see my Image Segmentation Tutorial for a full demo:
In short:
% Get centroids of all regions:
props = regionprops(mask, 'Centroid');
% Get a list of (x,y) centroids - each centroid in one row
xyCentroids = vertcat(props.Centroid);
x = xyCentroids(:, 1);
y = xyCentroids(:, 2);
% Get distances between every centroid and every other centroid:
distanceMatrix = pdist2(xyCentroids, xyCentroids);
% Just so we know what blob has what label,
% let's label them in the overlay above the image.
hold on;
for k = 1 : length(x)
plot(x(k), y(k), 'r+', 'MarkerSize', 40);
str = sprintf(' %d = (%.1f, %.1f)', k, x(k), y(k));
text(x(k), y(k), str, 'Color', 'r', 'FontSize', 15, 'FontWeight', 'bold');
end
hold off;
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!