v9.1.1
Menu

Procrustes Alignment Error

mediumPROLeast Squares AlignmentAlignmentCV: Image Alignment and Stitching

You are given two sets of corresponding 2D points and need to compute the alignment error (sum of squared distances between corresponding points).

After aligning point sets (e.g., by centering at origin), the alignment error measures how well they match:

E=∑i=1n∥pi−qi∥2=∑i=1n[(px,i−qx,i)2+(py,i−qy,i)2]E = \sum_{i=1}^{n} \|p_i - q_i\|^2 = \sum_{i=1}^{n} [(p_{x,i} - q_{x,i})^2 + (p_{y,i} - q_{y,i})^2]

This is used in:

  • Procrustes analysis for shape matching
  • ICP convergence checking
  • Evaluating transformation quality

Lower error means better alignment.

Example

Input
points1 = [(0, 0), (1, 0)]
points2 = [(0, 0), (1, 0.1)]
Output
0.01
Reasoning
  • Inputs: points1 and points2 each hold n=2n = 2 points in the plane, paired by position: p1=(0,0)p_1 = (0, 0) goes with q1=(0,0)q_1 = (0, 0), and p2=(1,0)p_2 = (1, 0) goes with q2=(1,0.1)q_2 = (1, 0.1).
  • Pair 1: the points coincide, so both coordinate differences are 00 and ∥p1−q1∥2=02+02=0\|p_1 - q_1\|^2 = 0^2 + 0^2 = 0.
  • Pair 2: the xx difference is 1−1=01 - 1 = 0 and the yy difference is 0−0.1=−0.10 - 0.1 = -0.1, so ∥p2−q2∥2=02+(−0.1)2=0.01\|p_2 - q_2\|^2 = 0^2 + (-0.1)^2 = 0.01. Squaring makes the sign irrelevant.
  • Total: E=0+0.01=0.01E = 0 + 0.01 = 0.01, which stays 0.01 after rounding to 4 decimal places (rounding also cleans up tiny floating point noise in 0.120.1^2).
  • Notice: the error is a squared distance, not a distance. The second point is off by 0.10.1 units, yet contributes only 0.010.01; an offset of (1,1)(1, 1) would contribute 12+12=21^2 + 1^2 = 2. Identical sets give exactly 00.

Constraints

  • points1 and points2 are lists of corresponding (x, y) points of same length
  • Each point in points1 corresponds to the same-indexed point in points2
  • Return total squared error rounded to 4 decimal places

More from CV: Image Alignment and Stitching

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.