Get more exact x/y values from a curve fit

8 ビュー (過去 30 日間)
Stefan Lang
Stefan Lang 2020 年 10 月 7 日
コメント済み: Ameer Hamza 2020 年 10 月 7 日
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 件のコメント
Stefan Lang
Stefan Lang 2020 年 10 月 7 日
Now this seems to work, thanks a lot!
Ameer Hamza
Ameer Hamza 2020 年 10 月 7 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by