PIXELBANKv9.1.0
Menu

Affine Transformation of Points

Implement an affine transformation to map a list of 2D points using a given 2x3 transformation matrix. This process involves applying a linear transformation followed by a translation to each point.

The affine transformation is a fundamental concept in Computer Vision and Geometric Transformations, as it preserves straight lines and ratios of distances between points lying on a straight line. The transformation can be represented by the equation [x′y′]=M⋅[xy1]\begin{bmatrix} x' \\ y' \end{bmatrix} = M \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, where MM is the 2x3 transformation matrix and [xy1]\begin{bmatrix} x \\ y \\ 1 \end{bmatrix} is the point in homogeneous coordinates.

Here are the steps to apply the transformation:

  1. Convert each point to homogeneous coordinates by appending 1 to the coordinates.
  2. Multiply the resulting vector by the 2x3 transformation matrix. The main equation for this process is:
[x′y′]=[m00m01m02m10m11m12]⋅[xy1]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} m_{00} & m_{01} & m_{02} \\ m_{10} & m_{11} & m_{12} \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

This technique is widely used in image processing and computer vision applications.

Example:

Input:
M = [[1, 0, 5], [0, 1, 10]]
points = [[0, 0], [1, 1]]
Output:
[[5.0, 10.0], [6.0, 11.0]]
Reasoning:
  • We apply the affine transformation to the first point (0, 0) using the given matrix M=[1050110]M = \begin{bmatrix} 1 & 0 & 5 \\ 0 & 1 & 10 \end{bmatrix}: [x′y′]=[1∗0+0∗0+50∗0+1∗0+10]=[510]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1*0 + 0*0 + 5 \\ 0*0 + 1*0 + 10 \end{bmatrix} = \begin{bmatrix} 5 \\ 10 \end{bmatrix}.
  • Then, we apply the same transformation to the second point (1, 1): [x′y′]=[1∗1+0∗1+50∗1+1∗1+10]=[611]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1*1 + 0*1 + 5 \\ 0*1 + 1*1 + 10 \end{bmatrix} = \begin{bmatrix} 6 \\ 11 \end{bmatrix}.
  • The transformed points are then rounded to 4 decimal places, but since the results are already integers, they remain the same.
  • The final output is a list of the transformed points: [[5.0,10.0],[6.0,11.0]][[5.0, 10.0], [6.0, 11.0]].

Constraints:

  • M is a 2x3 matrix (list of 2 rows, each with 3 elements)
  • points is a list of [x, y] pairs
  • Return list of [x', y'] rounded to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.