我将平滑的样条拟合到形状的(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)是像素化的。