Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Luis de Juan
Luis de Juan le 31 Août 2022
Commenté : Bruno Luong le 31 Août 2022
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 commentaires
Image Analyst
Image Analyst le 31 Août 2022
When you say "in the image" do you mean in the graphical overlay above the image, or actually burned into the image pixels themselves (so the underlying image pixels are changed)?
Luis de Juan
Luis de Juan le 31 Août 2022
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

Connectez-vous pour commenter.

Réponses (2)

Karim le 31 Août 2022
Modifié(e) : Karim le 31 Août 2022
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 (mathworks.com)

Bruno Luong
Bruno Luong le 31 Août 2022
Modifié(e) : Bruno Luong le 31 Août 2022
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 commentaires
Luis de Juan
Luis de Juan le 31 Août 2022
That's it! But how I use BSFK? unrecognized function!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by