Connecting dots with spline or polinomial on an image to process it later

조회 수: 7(최근 30일)
I want to connect the blue dots using splines, polinomial or a smooth line. I have already their coordinates of the pixel matrix.
Can anyone help me?
  댓글 수: 6
Luis de Juan
Luis de Juan 2022년 8월 31일
I want to use that curve to measure lenghts of differents sections of the curve. I understand what you mean, but I don't really know the answer. I would say whatever option with which I could do measurements later

댓글을 달려면 로그인하십시오.


Karim 2022년 8월 31일
편집: Karim 2022년 8월 31일
There are multiple ways to do this, here is one example using a file exchange function to subsaple the spline and make a smooth plot.
% grid given by the OP
Grid = [190.500000000000 285.500000000000
224.059860054750 153.192111578190
232.581399572552 420.540399229369
402.508419392691 213.445258896098
451.535515792237 324.819236098713
337.277297466815 113.811071623683];
% figure to find the ordering of the grid
hold on
for i = 1:size(Grid,1)
text(Grid(i,1),Grid(i,2),[' ',num2str(i)])
hold off
grid on
% set up the order, add the first point at the end to close the loop
Order = [2 1 3 5 4 6 2];
% get the new grid
Grid = Grid(Order,:);
% create a spline trough the grid and evaluate it at 100 equal subpoints
% note the 'csape' option is used to indicate that the curve is a closed
% loop and the interpolation is spline based
GridFine = interparc(100,Grid(:,1),Grid(:,2),'csape');
% plot the fine grid
hold on
grid on
Note: this answer makes use of the following file exchange submission: interparc - File Exchange - MATLAB Central (

Bruno Luong
Bruno Luong 2022년 8월 31일
편집: Bruno Luong 2022년 8월 31일
Using Free knot spline available here
P = [ ...
190.500000000000 285.500000000000;
224.059860054750 153.192111578190;
232.581399572552 420.540399229369;
402.508419392691 213.445258896098;
451.535515792237 324.819236098713;
337.277297466815 113.811071623683 ]
% This is to reorder the point and make them wrap around
K = convhull(P);
P = P(K,:);
% Find the distance between point and cumulate them as as free parameters
d = cumsum([0; sqrt(sum(diff(P,1,1).^2,2))]);
% Spline interpolation with periodic to make a close curve
X = P(:,1);
Y = P(:,2);
options = struct('periodic', true, 'lambda', 1e-6);
ppx = BSFK(d, X, 4, 10, [], options);
ppy = BSFK(d, Y, 4, 10, [], options);
% Graphical check
di = linspace(min(d),max(d), 500);
xi = ppval(ppx, di);
yi = ppval(ppy, di);
close all
axis equal
  댓글 수: 6

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by