Calculating Perpendicular Distance Between Detected Edge and Smoothing Function

29 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

John D'Errico
John D'Errico el 15 de Nov. de 2024 a las 12:31
Editada: John D'Errico el 15 de Nov. de 2024 a las 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.

Más respuestas (1)

Image Analyst
Image Analyst el 15 de Nov. de 2024 a las 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 comentario
Kajetan Planötscher
Kajetan Planötscher el 19 de Nov. de 2024 a las 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by