Fitting smooth closed spline to scattered 2D points
39 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have a set of points scattered in a 2D plane. The points are scattered in a somwhat circular/elipptical way, but I would like to fit some arbitrarily (but smoothed) shaped spline. The points are distributed like:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151430/image.png)
To enable closing of a spline, the last and first data points are the same.
As said I would like to fit a closed smoothed spline to this curve. I've tried the cscvn-option giving me the below, but I would like something a bit more smoothened out (cscvn forces the spline to go exactly through each and every point):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151432/image.png)
Reading up in the help, csaps seem to enable smoothing (to be fair, I'm not really sure how), but if trying this on my data I get a smoothed non-closed curve like below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151434/image.png)
The last option I've looked at is creating a new parameter to which I fit both my (x,y)-data (as suggested in an earlier thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/33868 ), but this actually gives me an even more jagged curve:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151436/image.png)
However I might be applying the parametrization in an incorrect way...
So, to my question. Does anyone have a good way of creating a closed smoothed spline to my data? Any suggestion or help would be very much appreciated. (P.S: I'm trying to create an automatized code, so I'm preferably looking for executable code than GUI in the curve fitting toolbox (but I understand that they are somewhat connected...)).
Thanks for the help!
/David
0 个评论
采纳的回答
Image Analyst
2015-6-21
If you don't want or require the curve to go through every point exactly, you can use a Savitzky-Golay filter on the parameterized data.
% Now smooth with a Savitzky-Golay sliding polynomial filter
windowWidth = 35
polynomialOrder = 2
smoothX = sgolayfilt(x, polynomialOrder, windowWidth);
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
8 个评论
Image Analyst
2015-6-21
David you can use activecontour() - do you know what active contours (also know as snakes or balloons or alpha shapes, or at least related to them) are? Attached is an example of active contour. You can use poly2mask() to turn your points into a solid mask, then use activecontour to create a smooth boundary. This uses an energy minimization method that perhaps you'll feel more comfortable with than polynomial regression (which is basically what sgolayfilt() is).
更多回答(1 个)
Praful Agrawal
2018-9-29
the original task can be achieved by converting the piecewise polynomial fit to bspline fit using fn2fm function:
X - set of points
pp = cscvn(X); bsp = fn2fm(pp, 'B-');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!