Connecting dots with spline or polinomial on an image to process it later
1 回表示 (過去 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 件のコメント
Image Analyst
2022 年 8 月 31 日
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)?
回答 (2 件)
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
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 件のコメント
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
plot(xi,yi,'b',X,Y,'or')
axis equal
set('Ydir','reverse')
6 件のコメント
Bruno Luong
2022 年 8 月 31 日
BSFK is on File exchange https://uk.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
参考
カテゴリ
Help Center および File Exchange で Splines についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!