v9.1.1
Menu

Compose Transformations

mediumFREE2D/3D TransformationsGeometryCV: Image Formation

Implement a function to compose multiple 2D transformations by multiplying their matrices, which is essential in computer vision for tasks like image formation and object recognition. This process involves combining various transformations such as rotation, scaling, and translation.

The concept of transformation matrices is crucial here, where each matrix TiT_i represents a specific transformation. The combined transformation is obtained by multiplying these matrices in a specific order, which is important due to the non-commutative nature of matrix multiplication.

The first matrix in the list, T1T_1, is applied to a point first, and the last one, TnT_n, is applied last. The key to this process is understanding how matrix multiplication works and how it applies to 2D transformations.

Tcombined=Tn⋅Tn−1⋅...⋅T1T_{combined} = T_n \cdot T_{n-1} \cdot... \cdot T_1

Return the composed 3×33 \times 3 matrix as a list of lists. This technique is widely used in image processing and robotics.

Example

Input
compose([[[1,0,5],[0,1,0],[0,0,1]], [[2,0,0],[0,2,0],[0,0,1]]])
Output
[[2,0,10],[0,2,0],[0,0,1]]
Reasoning
  • Input: a list of 3×33 \times 3 homogeneous matrices in the order they are applied to a point. Here T1=[105010001]T_1 = \begin{bmatrix}1&0&5\\0&1&0\\0&0&1\end{bmatrix} shifts xx by 5, and T2=[200020001]T_2 = \begin{bmatrix}2&0&0\\0&2&0\\0&0&1\end{bmatrix} doubles both coordinates.
  • Math: the transform applied last sits on the left, so Tcombined=T2⋅T1T_{combined} = T_2 \cdot T_1. Each entry is row ii of T2T_2 dotted with column jj of T1T_1.
  • Top-right entry: 2⋅5+0⋅0+0⋅1=102\cdot5 + 0\cdot0 + 0\cdot1 = 10. The diagonal gives 2⋅1=22\cdot1 = 2 twice, and the bottom row stays [0,0,1][0, 0, 1], giving [[2,0,10],[0,2,0],[0,0,1]].
  • Check on a point: (1,1)(1, 1) is shifted to (6,1)(6, 1), then scaled to (12,2)(12, 2); the combined matrix sends (1,1)(1,1) to (2⋅1+10, 2⋅1)=(12,2)(2\cdot1 + 10,\ 2\cdot1) = (12, 2) directly.
  • Notice: the shift became 10, not 5, because the scaling acts on the translation too. In the reverse order (scale first, then shift) the product is [205020001]\begin{bmatrix}2&0&5\\0&2&0\\0&0&1\end{bmatrix}: order matters.

Constraints

  • Input is a list of 3×3 matrices
  • Return the composed transformation matrix

Learn this in

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.