Calculating Perpendicular Distance Between Detected Edge and Smoothing Function
29 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kajetan Planötscher
il 15 Nov 2024 alle 12:09
Commentato: Kajetan Planötscher
il 19 Nov 2024 alle 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 Commenti
Risposta accettata
John D'Errico
il 15 Nov 2024 alle 12:31
Modificato: John D'Errico
il 15 Nov 2024 alle 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.
Più risposte (1)
Image Analyst
il 15 Nov 2024 alle 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
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!