Distances between regions in matlab
Mostrar comentarios más antiguos
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.
Respuestas (1)
Image Analyst
el 1 de Jul. de 2013
0 votos
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 comentarios
Zaid B
el 22 de En. de 2022
Hi , do you have the matlab code for this ..please?
Image Analyst
el 22 de En. de 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;
Categorías
Más información sobre Region and Image Properties en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!