MATLAB: Mean surface distance and residual mean square distance of 2 borders

digital image processingimage analysisimage processingimage segmentation

hi every body. I have 2 borders of 2 surfaces called S1 and S2. I need to compute the surface distance and after that the mean surface distance and residual mean square distance from that.
A complete description of the concept and the code in python is presented in https://mlnotebook.github.io/post/surface-distance-function/
Is there any matlab code for that?
Thanks in advance

Best Answer

You can simply use sqrt() and min():
x1 = S1(:, 1);
y1 = S1(:, 2);
x2 = S2(:, 1);
y2 = S2(:, 2);
for k = 1 : length(S1)
% Get the distance from the kth point of S1 to all points in S2.
distances = sqrt((x1(k) - x2) .^ 2 + (y1(k) - y2) .^ 2);
% Find the min of those distances to find how how close point k came to curve 2
minDistance(k) = min(distances);
end
If you have 3-D (x,y,z) coordinates, the extension to 3-D should be obvious.