# Is it valid to compose affine and perspective transformation matrices?

According to image processing literature, it is valid to compose multiple affine transformation matrices in order to apply just one transformation matrix to an image instead of subsequently applying all of the matrices.

Is it also valid to compose two different types of transformation matrices, for example an affine transformation matrix $A$ and a perspective transformation matrix $P$ (which is non-linear) $A \cdot P$?

If not, is there another way to merge these transformation into one matrix?

-

It is a basic fact of mathematics that given $r$ maps $f_i: X_{i-1}\to X_i$ $\ (1\leq i\leq r)$ one can apply these maps in turn to arbitrary points $x\in X_0$ and gets as output a point $y\in X_r$ which is defined by $$y=f_r\Bigl(f_{r-1}\bigl(\ldots f_2(f_1(x))\ldots\bigr)\Bigr)\ .$$ In this way a map $$\phi:\quad X_0\to X_r, \quad x\mapsto y$$ is generated, and one writes $\phi:=f_r\circ f_{r-1}\circ\ldots\circ f_1$.
This $\phi$ is a well-defined mathematical object by itself. As it leads directly from $x\in X_0$ to $y\in X_r$ the individual $f_i$ will no longer be visible in its expression (and can in fact be discarded). The actual expression of $\phi$ depends on circumstances. When, e.g., all $f_i$ are linear (or affine) maps then $\phi$ is such a map as well and can be expressed by a matrix (plus a constant vector). When the $f_i$ are defined in more complicated ways the resulting expression for $\phi$ will be more complicated, too. But in any case the expression of $\phi$, taking the encoding of an arbitrary $x\in X_0$ as input (e.g., $x=(x_1,x_2,x_3)$) and giving the encoding of the image point $y:=\phi(x)$ as output, can be computed once and for all.