Matlab 从平滑样条曲线拟合计算曲率

Matlab 从平滑样条曲线拟合计算曲率,matlab,curve-fitting,smoothing,Matlab,Curve Fitting,Smoothing,我将平滑样条曲线拟合到一个形状的(x,y)闭合轮廓上,我想找到该形状的局部曲率。我得到的曲率非常嘈杂,我相信有更好的方法 % Calculate the arc length along the shape s = cumsum(sqrt([0,diff(x)].^2 + [0 diff(y)].^2)); % Overlap when fitting to get end gradient correct s_fit = [s-max(s); s; s+max(s)]; x_fit = [x

我将平滑样条曲线拟合到一个形状的(x,y)闭合轮廓上,我想找到该形状的局部曲率。我得到的曲率非常嘈杂,我相信有更好的方法

% Calculate the arc length along the shape
s = cumsum(sqrt([0,diff(x)].^2 + [0 diff(y)].^2));

% Overlap when fitting to get end gradient correct
s_fit = [s-max(s); s; s+max(s)];
x_fit = [x x x]; y_fit = [y y y];

% Find parametric spline fit
fx = fit(s_fit,x_fit','smoothingspline','SmoothingParam',0.1);
fy = fit(s_fit,y_fit','smoothingspline','SmoothingParam',0.1);

% Differentiate fit at discrete points
ds = linspace(0,max(s),1000);
[dx_ds,ddx_ds] = differentiate(fx,ds);
[dy_ds,ddy_ds] = differentiate(fy,ds);

% Calculate signed curvature
curvature = (dx_ds.*ddy_ds - dy_ds.*ddx_ds)./(dx_ds.^2+dy_ds.^2).^(3/2);
计算得到的曲率大致正确,但相当混乱。我需要平滑样条线,因为我以(x,y)开始的轮廓是像素化的