Calculating center of rotation from Affine2D transformation matrix

52 views Asked by At

I have two 2D images, where the second one undergoes translation and rotation, resulting the coordinates (xn, yn) in the first picture to move to (xn', yn').

I have no problem obtaining the rotation angle, translation and scaling factor from the translation matrix described below. The rotation center however is not at the center of the image, and it is quite far from the images position. I might do a bad job on trying to draw the problem, but it looks like the picture attached:

The attached picture

I am trying to find the center of rotation from the transformation matrix obtained from cv2.estimateAffinePartial2D, which is↓

s*cos(theta), -s*sin(theta), Tx
s*sin(theta),  s*cos(theta), Ty

where s is scaling factor, theta is the rotation angle, Tx and Ty is translation on x axis and y axis respectively.

I tried calculating it by solving the equation below↓

Tx = (1-a)*Cx - b*Cy
Ty = b*Cx + (1-a)*Cy

where Cx and Cy is the center of the rotation and...

a = s*cos(theta)
b = s*sin(theta)

but I am not sure if this is correct.

Am I doing this wrong?

Equation to calculate the center of the rotation from the transformation matrix I give above.

EDIT: the (xn,yn) and (xn', yn') is known sets of coordinates, that are random points inside the small blue rectangle, not necessarily the center. I am sorry for the lack of explanation. They are like [[x1,y1],[x2,y2]...[xn.yn]], and similar points that have been translated and rotated to [[x1',y1'],[x2',y2']...[xn',yn']].

1

There are 1 answers

3
Bloux On

I am assuming that the points (xn, yn) and (xn', yn') are known.
By reusing your variable names, the correct equation you are looking for is :

xn' = a.xn + b.yn  + (1-a)Cx -b.Cy + Tx
yn' = -b.xn + a.yn + b.Cx + (1-a)Cy + Ty

As you mentioned that all other parameters were also known, you only need one point (can be any, as long as you are sure that these are the same point on both images) to solve for Cx and Cy:

Cx = (xn' - a.xn - b.yn + b.Cy - Tx)/(1-a)
Cy = (yn' + b.xn - a.yn - b.Cx - Ty)/(1-a)

This should be enough to compute Cx and Cy.
Hope this helps!