Calculating Perpendicular Distance Between Detected Edge and Smoothing Function

29 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

John D'Errico
John D'Errico am 15 Nov. 2024 um 12:31
Bearbeitet: John D'Errico am 15 Nov. 2024 um 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.

Weitere Antworten (1)

Image Analyst
Image Analyst am 15 Nov. 2024 um 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
  1 Kommentar
Kajetan Planötscher
Kajetan Planötscher am 19 Nov. 2024 um 7:17
Thank you for the suggestion. However, if I understand it correctly, the code only determines the minimum distance to a point, but without the constraint that the perpendicular distance with respect to the orange line is searched for.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by