Python 从两组点得到变换矩阵

Python get transformation matrix from two sets of points

我要图片,一张模拟,一张真实数据,有亮点。

模拟:

现实:

我可以很好地检测到斑点并获得坐标。现在我需要计算两个坐标系之间的变换矩阵(缩放、旋转、平移,也许还有剪切)。如果需要,我可以手工挑选一些(5-10)个对应的点来给算法

我已经尝试了很多方法,包括: ICP的2个实现: https://engineering.purdue.edu/kak/distICP/ICP-2.0.html#ICP

https://github.com/KojiKobayashi/iterative_closest_point_2d

实施仿射变换: https://math.stackexchange.com/questions/222113/given-3-points-of-a-rigid-body-in-space-how-do-i-find-the-corresponding-orienta/222170#222170

仿射变换的实现: Determining a homogeneous affine transformation matrix from six points in 3D using Python

how to perform coordinates affine transformation using python? part 2

他们中的大多数人都像这样以某种方式失败: 红色点是模拟转换到现实坐标系中的点。

目前最好的方法是这个 how to perform coordinates affine transformation using python? part 2 产生这个:

如您所见,缩放和平移大部分都有效,但图像仍需要旋转/镜像。

关于如何获得工作算法的任何想法?如果需要,我可以提供我当前的非工作实现,但它们基本上是链接的。

我发现了错误。

我使用 plt.imshow 来显示模拟图像和真实图像,然后从那里选择参考点来计算变换。

事实证明,由于通常的 array-to-image-index-flipping-voodoo(或者我这边对转换的错误理解),我需要将参考点的 x 和 y 索引从模拟图像。

有了这个,使用这个 how to perform coordinates affine transformation using python? part 2

一切正常