B样条拟合到2D离散数据点(轮廓图像的像素) [英] B-spline fitting to 2D discrete data points (pixels of contour image)

查看:512
本文介绍了B样条拟合到2D离散数据点(轮廓图像的像素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将B样条拟合到一组有序的离散数据点,这些数据点表示从图像中提取的轮廓的像素。

I am trying to fit a B-spline to a set of ordered discrete data points which represent pixels of a contour extracted from an image.

下面的代码适用于某些简单的形状,但不适用于其他形状(请参阅附图中的示例)。为什么会发生这种情况,以及解决此问题的更好方法是什么?

While the below code works fine for some simple shapes, but not for others (please see attached image for examples). Why does this happen, and what would be a better way to approach this problem?

我对差异几何是一个新手,欣赏任何见解或输入。谢谢。

I am quite new to differential geometry, appreciate any insights or inputs. Thanks.

% data contains two columns representing x,y coordinates of pixels
x = data(:, 1); 
y = data(:, 2); 
plot(x, y, 'bo');
fittedmodel = fit(x, y, 'cubicinterp');
plot(fittedmodel, 'r-');

推荐答案

出了什么问题?



你有两组数字 x y ,两组中的元素数量相同。

你假设:

a。有一个函数 f 这样所有对的 f(x_i)= y_i x_i ,y_i 在你的套装中。

b。集合中的点是有序的:也就是说,如果你遵循 f(x)的曲线,那么 x_i 来之前 x_ {i + 1}

What went wrong?

You have two sets of numbers x and y with the same number of elements in both sets.
You assume:
a. That there is a function f such that f( x_i ) = y_i for all pairs x_i,y_i in your sets.
b. That the points in the set are ordered: that is, if you follow the curve of f(x) then x_i "comes before" x_{i+1}.

虽然这些假设适用于正确的拟合示例你有。对于错误拟合示例,它们不再有效

正如您自己看到的那样,顶部上的输入轮廓无法表达as y = f(x)因为有两个 x 的值>可能的相应值 y (参见数学函数的定义)。你得到的拟合是与数学函数最接近的东西 y = f(x)可以给对 x,y 你给了(红色曲线的属性为每个 x 只有一个 y 值)。

While these assumptions hold for the "correct fit" example you have. They are no longer valid for the "incorrect fit" example.
As you can see for yourself, the input contour on the top cannot be expressed as y = f(x) since there are values of x for which there are two possible corresponding values of y (see the definition of mathematical function). The fit you got is the closest thing to a mathematical function y = f(x) that can be given the pairs x,y you gave (the red curve has the property of each x having only one y value).

在大多数情况下,当你尝试拟合2D曲线时,你会搜索参数曲线:也就是说,你引入了一个辅助参数 t 对于某些 0< = t< = 1 [x(t),y(t)] c $ c>。

现在,如果假设b成立(并且通过查看你的例子,我不确定它是什么),你可以做的是

In most cases when you try and fit a 2D curve you search for a parametric curve: that is, you introduce an auxilary parameter t such that each point along the curve can be represented as [x(t), y(t)] for some 0<=t<=1.
Now, if assumption b holds (and by looking at your examples, I'm not certain it is), what you can do is

 t = linspace( 0, 1, numel(x) ); % define the parameter t
 fitX = fit( t, x, 'cubicinterp'); % fit x as a function of parameter t
 fitY = fit( t, y, 'cubicinterp'); % fit y as a function of parameter t
 plot( fitX, fitY, 'r-' ); % plot the parametric curve

这篇关于B样条拟合到2D离散数据点(轮廓图像的像素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆