Calculating Perpendicular Distance Between Detected Edge and Smoothing Function
29 views (last 30 days)
Show older comments
Kajetan Planötscher
on 15 Nov 2024 at 12:09
Commented: Kajetan Planötscher
on 19 Nov 2024 at 7:17
The following picture shows an edge detected (yellow line) and a smoothing function approximating the detected edge (orange line). I want to determine the distance between the orange and the yellow line perpendicular to the orange line for each point of the yellow line. The yellow line is a nx2 double vector with x and y values, whereas the orange line is a curve created by the cscvn function. I attached both lines as .mat files. However, I neither found a suitable thread helping me out with this problem, nor did I come up with a solution myself. I would be very happy to get some suggestions on how to solve the issue. Thanks a lot!
0 Comments
Accepted Answer
John D'Errico
on 15 Nov 2024 at 12:31
Edited: John D'Errico
on 15 Nov 2024 at 12:40
If your curve is represented as a sequence of points (which is always possible) then you can use my distance2curve utility. It finds the closest point on such a curve, by repreenting the sequence of points as a spline, then finds the closest point to that spline model.
Find distance2curve on the File Exchange.
For example, I used the code, starting with a set of points on an ellipse, so the small circles. Then for any other point using distance2curve, it finds the closest point on a curve (in a perpendicular sense) that passes through the points I provided. It returns the projected nearest point, as well as the distance.
More Answers (1)
Image Analyst
on 15 Nov 2024 at 13:03
You could just do a brute force search. Here is untested code.
closestDistances = zeros(1, numel(redx));
for k = 1 : numel(redx)
% Get distances of this red point to all other yellow points.
allDistances = sqrt((redx(k) - yellowx) .^ 2 + (redy(k) - yellowy) .^ 2);
% Assign the minimum distance to our output vector.
closestDistances(k) = min(allDistances);
end
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!