我正在寻找一个函数,它可以使用PiecewiseAffineTransform的所有转换矩阵来应用于源数据,从而在一次运行中获得目标数据。我可以使用分段变换,同时也找不到使用所有变换矩阵的函数,这段代码可以在一个循环中使用所有的变换矩阵,这不是正确的方法,我还在skimage包中给出了估计的变换矩阵的所有函数。
import numpy as np
from skimage import transform as tf
from sklearn.metrics import mean_squared_error
from skimage.transform import PiecewiseAffineTransform
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('piecewise-affine', src, dst)
print(src)
print(dst)
print(tform.affines[0].params)
print(tform.affines[1].params)
mt = tf.matrix_transform(src, tform.affines[0].params)
print(mt)
>>> dir(tform)
['__add__', '__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_inverse_tesselation', '_tesselation', 'affines', 'estimate', 'inverse', 'inverse_affines', 'residuals']发布于 2017-11-12 20:24:37
只需使用源数据作为参数调用tform对象(请参阅geometric.py#L871):
In []: src
Out[]:
array([[0, 0],
[1, 0],
[1, 1],
[0, 1]])
In []: tform(src)
Out[]:
array([[ 3., 1.],
[ 3., 2.],
[ 2., 2.],
[ 2., 1.]])https://stackoverflow.com/questions/47229017
复制相似问题