找到两个2D数据点的最佳变换矩阵

时间:2017-11-01 21:04:55

标签: python-3.x scikit-learn scikit-image

如何找到最佳变换矩阵以对齐两个2D点集以获得最小均方误差值。这段代码就是我所做的,但这不对:tform * src。

import numpy as np
from skimage import transform as tf
from sklearn.metrics import mean_squared_error
# estimate transformation parameters
src = np.array([0, 0, 10, 10]).reshape((2, 2))
dst = np.array([12, 14, 1, -20]).reshape((2, 2))
tform = tf.estimate_transform('similarity', src, dst)
print(src)
print(dst)
print(tform.params)
msq=mean_squared_error(tform*src,dst)

1 个答案:

答案 0 :(得分:0)

最后我能为我的问题找到正确的答案

import numpy as np
from skimage import transform as tf
from sklearn.metrics import mean_squared_error
# estimate transformation parameters
src = np.array([0,0 , 1,0 , 1,1 , 0,1]).reshape((4, 2))
dst = np.array([3,1 , 3,2 , 2,2 , 2,1]).reshape((4, 2))
tform = tf.estimate_transform('similarity', src, dst)
#tform is the transformation matrix for these data to align them
print(src)
print(dst)
print(tform.params)

mt = tf.matrix_transform(src, tform.params)#mt is the same dst
mean_squared_error(mt,dst) #should be zero
print( '{:.10f}'.format(mean_squared_error(mt,dst)) )