[Math] Image Processing; find transformation matrix (Rot, Trans)

image processinglinear-transformationsmatrices

Hopefully this is a simple question; linear algebra is not my strong suit.

I am correlating two greyscale images based on their unique values (0-255) and the position of said values in matrix form. I have separated each image into multiple matrices based on corresponding greyscale values found in both images.

I am trying to re-align the images based on the translation/rotation of these greyscale values from image to image.

My question then; given two matrices (images)

Matrix A for greyscale value (50) = ([5,3],[4,8],[2,1],[0,9])

Matrix B for greyscale value (50) = ([2,2],[7,14],[4,3],[5,10])

Can I find a matrix of transformation such that we can extract a translation matrix and rotation matrix?

Edit: Sorry these are just example matrices, they will all be nx2 matrices, though I am considering padding out the matrices with zeros to make it nxn – will that help?

Best Answer

As I googled, I think I realized what you need. Every row is a 2D point. So "rotation" and "translation" are performed to EVERY row. So given two sets of points written in the matrices $A$ and $B$ you want to find a rotation matrix $R = \left(\begin{matrix} \cos{T} & -\sin{T} \\ \sin{T} & \cos{T} \end{matrix}\right)$ and a translation vector $tr = (t_x, t_y)^t$ such that for every row $B_i$ of $B$ and every row $A_i$ of $A$ you have $B_i^t = R.A_i^t + tr$.

Now, if $R$ and $tr$ exist and if you have two distinct rows from $B$ and $A$ you will have that

$$ B_1^t = R.A_1^t+tr, \qquad B_2^t = R.A_2^t+tr$$

from where after subtraction you will obtain $B_2^t-B_1^t = R.(A_2^t-A_1^t)$ which is a $2\times 2$ linear system for the "variables" $\cos{T}$ and $\sin{T}$. If your points are distinct, you will obtain unique solution for $R$ (and you know that an angle $T$ is determined uniquely by its $\sin$ and $\cos$). Once you have $R$ determined you obtain $tr$ from the first equation: $tr = B_1^t-R.A_1^t$.

Related Question