How to calculate what matrix will transform specified points to other specified points I want to transform an image.
As far as I was able to find out, I can achieve this with a matrix, right?
So here is my problem: how do I get this matrix if the only thing I know are the following starting and ending points?
$$\begin{matrix}
\text{Starting Points} & \text{Target Points} \\
\mathrm{TL}(3,5)     &    \mathrm{TL}'(0,3) \\
\mathrm{TR}(5,5)     &    \mathrm{TR}'(3,3) \\
\mathrm{LL}(2,2)     &    \mathrm{LL}'(0,0) \\
\mathrm{LR}(6,1)     &    \mathrm{LR}'(3,0)
\end{matrix}$$

 A: Let's look for an affine transformation to do what you like. This transformation will act on points in the plane (vectors in $\mathbb{R}^2$) and produce points in the plane, and will be given by $T(\vec{x}) = A \vec{x} + \vec{v}$ for some matrix $A$ and vector $\vec{v}$ which we shall find. Since we take points in the plane and produce points in the plane, $A$ must be $2 \times 2$, say with entries $a,b,c,d$ and $\vec{v}$ is also in the plane, with entries $e,f$.
Now your points give us 8 constraints on 6 variables $a,b,c,d,e,f$ - let's write down a couple and you can finish the rest and just solve the resulting system of linear equations (say, by Gaussian Elimination, or by Wolfram Alpha).
First point maps $(3,5) \to (0,3)$ so
$$
3a+5b+e = 0 \text{ and } 3c+5d+f = 3
$$
Second point maps $(5,5) \to (3,3)$ so
$$
5a+5b+e = 3 \text{ and } 5c+5d+f = 3
$$
Third point maps $(2,2) \to (0,0)$ so
$$
2a+2b+e = 0 \text{ and } 2c+2d+f = 0
$$
Fourth point maps $(1,6) \to (3,0)$ so
$$
1a+6b+e = 3 \text{ and } 1c+6d+f = 0
$$
Summarizing we get to solve
$$
\begin{bmatrix}
3 & 5 & 1 \\
5 & 5 & 1 \\
2 & 2 & 1 \\
1 & 6 & 1
\end{bmatrix}
\begin{bmatrix} a & c\\ b & d\\ e & f\end{bmatrix}
= \begin{bmatrix} 0 & 3\\ 3 & 3 \\ 0 & 0 \\ 3 & 0\end{bmatrix}
$$
You can use the first three to solve and plug it into the fourth to check it.
A: What you're (presumably) looking to perform is called an affine transformation. An affine transformation in two dimensions is determined by how three points transform. So there may or may not be one that does what you want here. It's possible (and very common in computer graphics) to represent an affine transformation as a linear transformation by adding an extra dimension, but at this juncture I would speculate that you're probably better off sticking to the affine form for right now.
A: You did not specify if you are looking for a linear transform or other? Since you mention matrix and no functions of start points, I am assuming it is a linear one you want.
Since you don't specify any other conditions (e.g., preservation of length, angles, etc.), your x- and y-coordinates do not need to be related by extra conditions, so you can write each start point as $(x_i,y_i)$ and each target point as $(x^\prime_i,y^\prime_i)$. Define $\bf{X} = [x_1 ... x_4 y_1 ... y_4]$ and $\bf{Y} = [x^\prime_1 ... x^\prime_4 y^\prime_1 ... y^\prime_4]$. Then you can set up an $8\times 8$ linear system $\bf{Y} = A \cdot \bf{X}$ with the elements of the matrix $A$ as unknowns. However, you will need to specify 4 more dummy points and their images to obtain a possible matrix solution.
