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 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