Get more exact x/y values from a curve fit

8 次查看(过去 30 天)
I have some some point coordinates, that i get from annotation in an image. Let's say these are my x and y values.
x = (1:50);
y = x + randi(10,1,50) + sin(x);
Now i fit these
fitted = fit(x',y','smoothingspline');
To get the y values, i do
y_fit(:,1) = feval(fitted, x);
Plot returns a fitted curve with 50 points, but i need a much smoother curve fit. I need around 1000 x/y values from 10 annotated points.
plot(x,y)
hold on
plot(x,y_fit)
Now in my actual problems, i have e.g. 10 x values distributed over 1000 pixels. If i eval my fitted function, only get 10 y values back, but i need much more precise coordinates, to get a very smooth line through these 10 points, and not just connect 10 points in a linear manner. Goal is to annotate around 20 points in an 5000x2000 pixel image, fit a circle/polygon through these 20 points and use poly2mask() to get a logical array. But the circle should not just be a connection of the 20 points, but a much smoother curve.

采纳的回答

Ameer Hamza
Ameer Hamza 2020-10-7
编辑:Ameer Hamza 2020-10-7
What about fitting a low-order polynomial through your data-points
x = (1:50);
y = x + randi(10,1,50) + sin(x);
fitted = fit(x',y','poly4');
y_fit(:,1) = fitted(x); % this syntax is also valid
plot(x,y)
hold on
plot(x,y_fit)
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by