v9.1.1
Menu

Homography Point Transformation

hardPROGeometric TransformationsComputer Vision 2

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
  • H is a 3×33 \times 3 matrix describing a planar perspective mapping; points holds two 2D points, (1,2)(1, 2) and (3,4)(3, 4), in pixel-style coordinates.
  • Here HH is the identity: ones on the diagonal, zeros elsewhere. The top-left 2×22 \times 2 block (no rotation or scaling), the last column (zero translation) and the bottom row [0,0,1][0, 0, 1] (no perspective) all say "change nothing".
  • Lifting (1,2)(1, 2) to homogeneous form gives [1,2,1]T[1, 2, 1]^T. Each output row is a dot product with that vector: 1⋅1+0⋅2+0⋅1=11\cdot1 + 0\cdot2 + 0\cdot1 = 1, then 22, and the third component is w=0⋅1+0⋅2+1⋅1=1w = 0\cdot1 + 0\cdot2 + 1\cdot1 = 1.
  • Dividing by w=1w = 1 leaves (1,2)(1, 2); the same arithmetic sends (3,4)(3, 4) to itself, giving [[1.0, 2.0], [3.0, 4.0]].
  • Notice the values print as 1.0, not 1: the perspective divide always produces real numbers, even when w=1w = 1. With a non-zero bottom row, ww would vary per point and points with larger ww would be pulled closer to the origin, which is exactly the perspective effect.

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

Learn this in

More from Computer Vision 2

PRO

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

Sign in to run your code against the test cases.