加权最小二乘 - 适合平面到三维点集小二、平面、适合

2023-09-11 03:53:54 作者:念卿.

我嵌合的平面到3D点集与最小二乘法。我已经有算法来做到这一点,但我想修改为使用加权最小二乘。这意味着我有一个权重的每个点(重量越大,越接近平面应的点)。

I am fitting a plane to a 3D point set with the least square method. I already have algorithm to do that, but I want to modify it to use weighted least square. Meaning I have a weight for each point (the bigger weight, the closer the plane should be to the point).

目前的算法(不计权)看起来是这样的:

The current algorithm (without weight) looks like this:

计算的总和:

for(Point3D p3d : pointCloud) {
    pos = p3d.getPosition();
    fSumX += pos[0];
    fSumY += pos[1];
    fSumZ += pos[2];
    fSumXX += pos[0]*pos[0];
    fSumXY += pos[0]*pos[1];
    fSumXZ += pos[0]*pos[2];
    fSumYY += pos[1]*pos[1];
    fSumYZ += pos[1]*pos[2];
}

不是使矩阵:

than make the matrices:

double[][] A = {
    {fSumXX, fSumXY, fSumX},
    {fSumXY, fSumYY, fSumY},
    {fSumX,  fSumY,  pointCloud.size()}
};

double[][] B =  {
    {fSumXZ},
    {fSumYZ},
    {fSumZ}
};

比解决AX = B和溶液的3组分拟合平原的系数...

than solve Ax = B and the 3 components of the solution are the coefficients of the fitted plain...

所以,可以请你帮我如何修改此使用权?谢谢!

So, can you please help me how to modify this to use weights? Thanks!

推荐答案

直觉

一个点 X N 在飞机上通过正常限定的平面与点 P 服从:ñ(X - P)= 0 。如果一个点不在飞机上,ñ。(Y -p)将不等于零,所以定义一个成本的有效途径是通过 |。N(Ÿ - P)| ^ 2 。这是该点的平方距离从飞机上。

A point x on a plane defined by normal n and a point on the plane p obeys: n.(x - p) = 0. If a point y does not lie on the plane, n.(y -p) will not be equal to zero, so a useful way to define a cost is by |n.(y - p)|^2 . This is the squared distance of the point y from the plane.

通过平等权,你要找到一个 N 的总结过点时,最大限度地减少了总方差:

With equal weights, you want to find an n that minimizes the total squared error when summing over the points:

f(n) = sum_i | n.(x_i - p) |^2

现在这一假设,我们知道的部分的点 P 位于该平面上。我们可以很容易地计算一个作为质心,这是简单地在点云的点的分量逐均值和将始终在于最小二乘平面

Now this assumes we know some point p that lies on the plane. We can easily compute one as the centroid, which is simply the component-wise mean of the points in the point cloud and will always lie in the least-squares plane.

解决方案

让我们定义一个矩阵 M 其中每行是第i x_i 减去重心 C ,我们可以重新写:

Let's define a matrix M where each row is the ith point x_i minus the centroid c, we can re-write:

f(n) = | M n |^2

您应该能够说服自己,这个矩阵乘法的版本是一样的previous方程的总和。

You should be able to convince yourself that this matrix multiplication version is the same as the sum on the previous equation.

您可以再取 M 和 N 你想,然后通过 M 对应于右奇异向量给出最小的奇异值。

You can then take singular value decomposition of M, and the n you want is then given by the right singular vector of M that corresponds to the smallest singular value.

要合并的权重,你只需要定义一个重量 w_i 的每一个点。计算 C 作为点的加权平均,并更改 sum_i | N(x_i - C)| ^ 2 sum_i | w_i * N(x_i - C)| ^ 2 ,并以类似的方式矩阵 M 。然后像以前一样解决。

To incorporate weights you simply need to define a weight w_i for each point. Calculate c as the weighted average of the points, and change sum_i | n.(x_i - c) |^2 to sum_i | w_i * n.(x_i - c) |^2, and the matrix M in a similar way. Then solve as before.