Connecting dots with spline or polinomial on an image to process it later
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 31 Ago 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)?
Risposte (2)
Karim
il 31 Ago 2022
Modificato: Karim
il 31 Ago 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
figure
scatter(Grid(:,1),Grid(:,2))
hold on
for i = 1:size(Grid,1)
text(Grid(i,1),Grid(i,2),[' ',num2str(i)])
end
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
figure
hold on
plot(GridFine(:,1),GridFine(:,2),'r','linewidth',2)
scatter(Grid(:,1),Grid(:,2),'b','filled')
grid on
Note: this answer makes use of the following file exchange submission: interparc - File Exchange - MATLAB Central (mathworks.com)
0 Commenti
Bruno Luong
il 31 Ago 2022
Modificato: Bruno Luong
il 31 Ago 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
plot(xi,yi,'b',X,Y,'or')
axis equal
set('Ydir','reverse')
6 Commenti
Bruno Luong
il 31 Ago 2022
BSFK is on File exchange https://uk.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
Vedere anche
Categorie
Scopri di più su Splines in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!