Professional Documents
Culture Documents
2023 15:40 How to find the centreline of two curves - MATLAB Answers - MATLAB Central
Take a track as an example, the X,Y coordinates of the inner and outer track boundary are given (no
MATLAB Answers
intersections, either closed or open). How can I calculate the centreline between the two boundaries or
two fitted curves. At each point on the centreline, the distance between the point and either curve
should be the same and can be called as the width of the track. My approach is to formulate a optimum
control problem but I want to know is there any other way to do that.
If (x1,y1) is a representation of the first curve and (x2,y2) is a representation of the second
curve, Image Analyst's suggestion is the simplest way to approach this problem.
Theme Copy
t = 0:100:2*pi;
x1 = 10*cos(t);
y1 = 10*sin(t);
x2 = 5*cos(t);
y2 = 5*sin(t);
Sign in to comment.
Answers (1)
What I'd to is to scan along one curve and for each point, find the distance to every point
on the other curve. Find the min distance and the index for that and then get the point on
the other curve that is closest and take the midpoint of a line going from curve 1 to curve 2.
Something like (untested):
https://www.mathworks.com/matlabcentral/answers/508300-how-to-find-the-centreline-of-two-curves 1/5
18.01.2023 15:40 How to find the centreline of two curves - MATLAB Answers - MATLAB Central
Theme Copy
for k = 1 : length(x1)
distances = sqrt((x1(k) - x2) .^ 2 + (y1(k) - y2) .^ 2);
[minDistance, indexOfMin] = min(distances);
xCenter(k) = mean([x1(k), x2(indexOfMin)]);
yCenter(k) = mean([y1(k), y2(indexOfMin)]);
end
% Now plot the centerline curve
hold on;
plot(xCenter, yCenter, 'b-', 'LineWidth', 2);
x1 and y1 are vectors of the coordinates of one curve, and x2 and y2 are the coordinates
of the second curve. xCenter and yCenter are the coordinates of the line between curve
#1 and curve #2.
Theme Copy
%========================================================================
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
markerSize = 4;
% Read in a standard MATLAB gray scale demo image.
fullFileName = 'cameraman.tif';
grayImage = imread(fullFileName);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized';
% User draws curve 1 on image here.
message = sprintf('Left click and hold to begin drawing a freehand path.\
uiwait(msgbox(message));
hFH = drawfreehand();
% Get the xy coordinates of where they drew.
xy = hFH.Position
% get rid of imfreehand remnant.
delete(hFH);
% Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
x1 = xy(:, 1);
y1 = xy(:, 2);
plot(x1, y1, 'r.', 'LineWidth', 2, 'MarkerSize', 12);
https://www.mathworks.com/matlabcentral/answers/508300-how-to-find-the-centreline-of-two-curves 2/5
18.01.2023 15:40 How to find the centreline of two curves - MATLAB Answers - MATLAB Central
https://www.mathworks.com/matlabcentral/answers/508300-how-to-find-the-centreline-of-two-curves 3/5
18.01.2023 15:40 How to find the centreline of two curves - MATLAB Answers - MATLAB Central
0 Comments
Sign in to comment.
See Also
MATLAB Answers
How can I separate the body from legs in the crab image
1 Answer
Entire Website
fasadi
File Exchange
b-spline recursion
File Exchange
Categories
Image Processing and Computer Vision ❯ Computer Vision Toolbox ❯ Point Cloud Processing
https://www.mathworks.com/matlabcentral/answers/508300-how-to-find-the-centreline-of-two-curves 4/5
18.01.2023 15:40 How to find the centreline of two curves - MATLAB Answers - MATLAB Central
Find more on Point Cloud Processing in Help Center and File Exchange
Tags
curve geometry centreline curvature curve fitting iso curve midline between cu...
Poll
Occasionally
Sometimes
Vote
mathworks.com
© 1994-2022 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional
trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.
https://www.mathworks.com/matlabcentral/answers/508300-how-to-find-the-centreline-of-two-curves 5/5