如何在图像上绘制圆弧/样条曲线并获得长度?

时间:2013-11-06 02:53:49

标签: matlab image-processing automatic-ref-counting spline

我可以使用点画一条线,但我不知道如何绘制曲线。

这是我的代码:

clc;
clear all;
I = imread('im6f.jpg');
figure,imshow(I);

[x,y] = ginput(2);

然后我用距离公式来得到长度。

我怎么做曲线?

1 个答案:

答案 0 :(得分:2)

如何使用interp1插入样条曲线?假设fold = 10是您想要的分辨率的近似增加。然后,[x, y] = ginput()没有特定的上限。用户指定的点数为n = length(x)。然后,

t = 1 : (1/fold) : n;
xi = interp1(1 : n, x, t, 'spline');
yi = interp1(1 : n, y, t, 'spline');
plot(xi, yi, 'linewidth', 3);

为您提供以下内容,其中红色斑点标记我点击的点。您必须按 Enter 才能停止收集坐标。

enter image description here

xiyifold - 使用x作为插值方法,重叠采样y'spline'的坐标。您可以查看this了解其他选项。

dx = xi(1 : end-1) - xi(2 : end);
dy = yi(1 : end-1) - yi(2 : end);
d = sum(sqrt(dx.^2 + dy.^2));

d大致是该样条曲线的长度,计算为所有边长度的总和。在上面显示的情况下,d = 118.97