1

我正在处理两个形状相似但还不完全相同的卷,里面有一个卷网格。我的目标是使我的第一卷(绿色)与我的第二卷(红色)相匹配。两者都有一个带有内部顶点的 ConvexHull ( http://scipy.github.io/devdocs/generated/scipy.spatial.ConvexHull.html )。我为两个卷创建了多个标记(参见图 1)以计算转换矩阵(https://community.esri.com/thread/183601-numpy-linalglstsq-coordinate-translations)

我的原始卷的卷网格数据结构是:

array([[ 0.025, -0.055, -0.03 ],
       [-0.01 , -0.05 , -0.03 ],
       [-0.005, -0.05 , -0.03 ],
       ..., 
       [-0.01 , -0.03 ,  0.1  ],
       [-0.01 , -0.025,  0.1  ],
       [-0.015, -0.02 ,  0.1  ]])

 ,     with the shape of `(12163, 3)`

我的原始卷的卷网格数据结构是:

array([[ 0.   , -0.055, -0.065],
       [ 0.005, -0.055, -0.065],
       [-0.005, -0.05 , -0.065],
       ..., 
       [-0.005, -0.02 ,  0.08 ],
       [ 0.   , -0.02 ,  0.08 ],
       [ 0.005, -0.02 ,  0.08 ]])

 ,     with the shape of `(14629, 3)`

图 1 - 两个 ConvexHull 体积的标记

应转换的原始标记的坐标为:

array([[-0.00307161, -0.01828496,  0.03521746],
       [-0.065     , -0.01828496,  0.03521746],
       [ 0.06      , -0.01828496,  0.03521746],
       [-0.00307161, -0.01828496,  0.1       ],
       [-0.00307161,  0.075     ,  0.03521746],
       [-0.00307161, -0.01828496, -0.03      ]])

模板标记是:

array([[ 0.00038417, -0.02389603,  0.00802208],
       [-0.07      , -0.02389603,  0.00802208],
       [ 0.07      , -0.02389603,  0.00802208],
       [ 0.00038417, -0.02389603,  0.08      ],
       [ 0.00038417,  0.07      ,  0.00802208],
       [ 0.00038417, -0.02389603, -0.065     ]])

我用我的标记的坐标点来计算变换矩阵,如:

print 'Calculating the transformation matrix..\n'

n = orig_marker.shape[0]
pad = lambda x: np.hstack([x, np.ones((x.shape[0], 1))])
unpad = lambda x: x[:,:-1]
trans_mat, res, rank, s = np.linalg.lstsq(pad(orig_marker), pad(temp_marker))


transform = lambda x: unpad(np.dot(pad(x), trans_mat))
trans_mat[np.abs(trans_mat) < 1e-10] = 0  # set really small values to zero
print 'trans matrix is:\n', trans_mat
trans_mat_inv = np.linalg.inv(trans_mat)

Out [1]:  trans matrix is [[  3.29770822e-02   1.06840729e-02   1.71325156e-03   0.00000000e+00]
     [ -7.56419706e-03   9.51696607e-03   3.51349962e-02   0.00000000e+00]
     [  5.32353680e-03   2.91946064e-01   8.44071139e-01   0.00000000e+00]
     [  1.96037928e-04  -3.51253282e-02  -3.05335725e-02   1.00000000e+00]]

之后,我通过以下方式将转换矩阵应用于我的体积网格点:

# apply rotation and scale
transformed_points = np.dot(orig_points, trans_mat[:3, :3].T)
# apply translation
transformed_points += trans_mat[:3, 3]
x_t, y_t, z_t = transformed_points.T

, whereorig_pointstemp_pointsare 我的体积的体积网格是x_t, y_t, z_t我转换的体积网格的坐标。

由于我应用了旋转、缩放和平移,我的体积网格应该匹配。不幸的是,我的体积网格仍然如图 2 所示: 在此处输入图像描述

我几乎可以肯定我的方法是正确的。我认为错误可能出在转换矩阵的计算中。

谁能看到出了什么问题或我在哪里犯了错误?

使用我自己制作的翻译,结果如下所示:

在此处输入图像描述

由于结果不准确,我希望正确计算我的转换矩阵。

4

0 回答 0