PIXELBANKv9.1.0
Menu

Homography Point Transformation

Implement a perspective transformation using a given 3x3 homography matrix HH on a list of 2D points. This process is crucial in Computer Vision for transforming images or points between different coordinate systems.

The concept of homography is based on the idea that two images of the same planar scene are related by a perspective transformation, which can be represented by a 3×33 \times 3 matrix HH. To apply this transformation to a point (x,y)(x, y), we first convert it to homogeneous coordinates.

Here are the steps to apply the transformation:

  1. Convert the point to homogeneous coordinates: p=[x,y,1]T\mathbf{p} = [x, y, 1]^T
  2. Apply the homography matrix: p′=H⋅p\mathbf{p'} = H \cdot \mathbf{p}
  3. Normalize the result: x′=p0′/p2′x' = p'_0 / p'_2, y′=p1′/p2′y' = p'_1 / p'_2
p′=[h11h12h13h21h22h23h31h32h33]⋅[xy1]\mathbf{p'} = \begin{bmatrix} h_{11} & h_{12} & h_{13} \\ h_{21} & h_{22} & h_{23} \\ h_{31} & h_{32} & h_{33} \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

This technique is widely used in image processing and Computer Vision applications.

Example:

Input:
H = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
points = [[1, 2], [3, 4]]
Output:
[[1.0, 2.0], [3.0, 4.0]]
Reasoning:
  • The given homography matrix HH is the identity matrix, meaning it doesn't alter the input points: H=[100010001]H = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}.
  • For each point (x,y)(x, y), we convert to homogeneous coordinates: p=[x,y,1]T\mathbf{p} = [x, y, 1]^T. For the points (1,2)(1, 2) and (3,4)(3, 4), we get p1=[1,2,1]T\mathbf{p_1} = [1, 2, 1]^T and p2=[3,4,1]T\mathbf{p_2} = [3, 4, 1]^T.
  • We multiply HH by each point: p′=Hâ‹…p\mathbf{p'} = H \cdot \mathbf{p}. Since HH is the identity matrix, p′=p\mathbf{p'} = \mathbf{p}, resulting in p1′=[1,2,1]T\mathbf{p'_1} = [1, 2, 1]^T and p2′=[3,4,1]T\mathbf{p'_2} = [3, 4, 1]^T.
  • Finally, we divide by the third coordinate (p2′p'_2) to get the transformed points: x′=p0′/p2′=xx' = p'_0 / p'_2 = x and y′=p1′/p2′=yy' = p'_1 / p'_2 = y, so the points remain (1,2)(1, 2) and (3,4)(3, 4), which when rounded to 4 decimal places are [1.0,2.0][1.0, 2.0] and [3.0,4.0][3.0, 4.0].

Constraints:

  • H is a 3x3 matrix
  • points is a list of [x, y] pairs
  • The third coordinate after multiplication will not be zero
  • 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.
Homography Point Transformation - Hard | PixelBank