简体   繁体   English

如何计算共形仿射变换?

[英]How to compute conformal affine transformation?

I'm working on an image registration problem, so after extraction of features points ( a set of 3 or 4 2D points), I have to compute the affine transformation matrix. 我正在研究图像配准问题,因此在提取特征点(一组3或4个2D点)之后,我必须计算仿射变换矩阵。

The affine transformation is by definition composed of scaling, translation, rotation and shering. 根据定义,仿射变换由缩放,平移,旋转和shering组成。 In my case, the transformation is conformal, which means no shiring is allowed. 在我的情况下,转换是保形的,这意味着不允许shiring。

All functions I've tried computes the affine transformation matrix with shearing, How can I achieve the conformal affine transformation ? 我试过的所有函数都用剪切来计算仿射变换矩阵,如何实现共形仿射变换?

Thank you 谢谢

You can fully define affine transformation in 2D by its action on 3 points that do not lie on one line. 您可以通过对不在一条线上的3个点的动作在2D中完全定义仿射变换。 A good explanation of why this is the case you may find in " Beginner's guide to mapping simplexes affinely ". 为什么会出现这种情况的一个很好的解释,你可以在“ 初学者指南简单地映射单一格式 ”中找到。 Besides, you may find there a very simple method to recover the transformation. 此外,您可能会发现一种非常简单的方法来恢复转换。 Following code illustrates the general idea (sorry for the codestyle -- I'm mathematician, not programmer) 下面的代码说明了一般的想法(抱歉代码风格 - 我是数学家,而不是程序员)

import numpy as np
# input data
ins = [[1, 1], [2, 3], [3, 2]]  # <- points
out = [[0, 2], [1, 2], [-2, -1]] # <- mapped to
# calculations
l = len(ins)
B = np.vstack([np.transpose(ins), np.ones(l)])
D = 1.0 / np.linalg.det(B)
entry = lambda r,d: np.linalg.det(np.delete(np.vstack([r, B]), (d+1), axis=0))
M = [[(-1)**i * D * entry(R, i) for i in range(l)] for R in np.transpose(out)]
A, t = np.hsplit(np.array(M), [l-1])
t = np.transpose(t)[0]
# output
print("Affine transformation matrix:\n", A)
print("Affine transformation translation vector:\n", t)
# unittests
print("TESTING:")
for p, P in zip(np.array(ins), np.array(out)):
  image_p = np.dot(A, p) + t
  result = "[OK]" if np.allclose(image_p, P) else "[ERROR]"
  print(p, " mapped to: ", image_p, " ; expected: ", P, result)

This code demonstrates how to recover affine transformation as matrix and vector and tests that initial points are mapped to where they should. 此代码演示了如何将仿射变换恢复为矩阵和向量,并测试初始点是否映射到它们应该的位置。 You can test this code with Google colab , so you don't have to install anything. 您可以使用Google colab测试此代码,因此您无需安装任何内容。

The same authors published " Workbook on mapping simplexes affinely " that contains many practical examples of this kind. 同一作者发表了“ 关于映射单纯形的工作手册 ”,其中包含许多此类实例。 If you would like to create your own implementation from scratch rather than modifying this one, you may want to check few examples in the workbook to see how one recovers affine transformation "by hands". 如果您想从头创建自己的实现而不是修改这个实现,您可能需要检查工作簿中的几个示例,以了解如何“手动”恢复仿射转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM