python - 分段变换

标签 python numpy scikit-image affinetransform piecewise

我正在寻找一个函数,它可以使用 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']

最佳答案

只需使用源数据作为参数调用 tform 对象(请参阅 https://github.com/scikit-image/scikit-image/blob/master/skimage/transform/_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.]])

关于python - 分段变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47229017/

相关文章:

python - numpy.linalg.eigh 与 numpy.linalg.svd 相比如何?

python - 将 numpy 数组保存为 SVG 格式

python - skimage.transform.rescale 将数据类型从 uint8 更改为 float64

python - 导入 skimage.io 时 TkInter 在 OSX 上崩溃

Python3打印原始字节

Python3 计算字符串中的 UTF-16 代码点

python - Pandas 函数耗时太长

具有条件的函数中的 Python- Numpy 数组

python - 将图像裁剪到对象区域的面积

python - 我正在尝试将类与 python 字典一起使用