简体   繁体   中英

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.

The affine transformation is by definition composed of scaling, translation, rotation and shering. In my case, the transformation is conformal, which means no shiring is allowed.

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. 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.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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