v9.1.1
Menu

2D Translation Matrix

easyFREE2D/3D TransformationsGeometryCV: Image Formation

Implement a 3×3 homogeneous transformation matrix for 2D translation, which is a fundamental concept in 2D/3D Transformations used to change the position of an object in a 2D space. This transformation is essential in Computer Vision for tasks such as image registration and object tracking.

The concept of homogeneous coordinates allows for efficient representation of geometric transformations, including translation, rotation, and scaling. In the context of 2D translation, a point (x,y)(x, y) is represented in homogeneous coordinates as (x,y,1)(x, y, 1), enabling the use of matrix multiplication to apply the transformation.

To create the transformation matrix, follow these steps:

  1. Initialize a 3×3 identity matrix.
  2. Update the last column with the translation values txt_x and tyt_y.
(10tx01ty001)\begin{pmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{pmatrix}

This technique is widely used in image processing applications.

Example

Input
translation_matrix(5, 3)
Output
[[1,0,5],[0,1,3],[0,0,1]]
Reasoning
  • Inputs: tx =5= 5 and ty =3= 3 are the shift along the xx-axis and the yy-axis. The result is a 3×33 \times 3 matrix that moves every 2D point by (5,3)(5, 3).
  • Fill in the form: the left 2×22 \times 2 block is the identity, so the shape is not stretched or rotated. The third column holds tx=5t_x = 5 and ty=3t_y = 3, and the bottom row stays (0,0,1)(0, 0, 1). That gives the output [[1,0,5],[0,1,3],[0,0,1]].
  • Check it on a point: write (2,1)(2, 1) as (2,1,1)(2, 1, 1). Row 1 gives 1⋅2+0⋅1+5⋅1=71\cdot2 + 0\cdot1 + 5\cdot1 = 7, row 2 gives 0⋅2+1⋅1+3⋅1=40\cdot2 + 1\cdot1 + 3\cdot1 = 4, and row 3 gives 11. So the point lands at (7,4)(7, 4), which is (2+5, 1+3)(2+5,\ 1+3).
  • Notice: the shift only works because of the extra coordinate 11. It multiplies the third column, which is why a 2×22 \times 2 matrix alone can't translate. With tx=ty=0t_x = t_y = 0 the matrix is just the 3×33 \times 3 identity.

Constraints

  • tx and ty are floating-point numbers
  • Return a 3×3 matrix

Learn this in

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.