Get more exact x/y values from a curve fit
17 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Ameer Hamza
on 7 Oct 2020
Edited: Ameer Hamza
on 7 Oct 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!