Translation and Scale
Least Squares
Point Sets
Distance Error
Geometric Transformation

Finding translation and scale on two sets of points to get least square error in their distance?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

In the realm of data analysis and computer vision, aligning two sets of points by finding an optimal translation and scale can be a critical task. This technique is frequently used for image registration, shape analysis, and other applications involving spatial transformations. The goal is to minimize the least square error between two sets of corresponding points by optimally translating and scaling them. This article delves into the nuances of this process, providing technical explanations, examples, and a comprehensive overview of the methodology.

Understanding the Problem

Given two sets of nn points, $P = \{p_1, p_2, \ldots, p_n\}$ and $Q = \{q_1, q_2, \ldots, q_n\}$, we aim to find a translation vector T=(tx,ty)T = (t_x, t_y) and a scale factor ss such that when applied to set PP, it minimizes the sum of squared distances to the corresponding points in set QQ. Mathematically, this can be formulated as:

minimize_i=1nsp_i+Tq_i2\text{minimize} \quad \sum\_{i=1}^{n} |sp\_i + T - q\_i|^2

Here, \| \cdot \| denotes the Euclidean norm. The task is to determine the optimal ss and TT.

Least Squares Methodology

To solve this optimization problem, we employ the least squares approach. The least squares method aims to find the parameters that minimize the difference between the observed values and those predicted by the model. Here, it involves several key steps:

  1. Center the Data: Start by translating both sets of points to their respective centroids. The centroids of the sets PP and QQ are given by:
    pˉ=1n_i=1np_i,qˉ=1n_i=1nq_i\bar{p} = \frac{1}{n} \sum\_{i=1}^{n} p\_i, \quad \bar{q} = \frac{1}{n} \sum\_{i=1}^{n} q\_i
    Translate the points by subtracting these centroids:
    p_i=p_ipˉ,q_i=q_iqˉp'\_i = p\_i - \bar{p}, \quad q'\_i = q\_i - \bar{q}
  2. Compute Scale: With the data centered, compute the scale factor ss that minimizes the sum of square distances. The optimal scale is given by:
    s=_i=1n(p_iqi)i=1np_i2s = \frac{\sum\_{i=1}^{n} (p'\_i \cdot q'*i)}{\sum*{i=1}^{n} |p'\_i|^2}
    where the dot product piqip'_i \cdot q'_i is the sum of products of the corresponding coordinates.
  3. Compute Translation: Once ss is known, the optimal translation vector TT can be calculated as:
    T=qˉspˉT = \bar{q} - s \bar{p}

By using these steps, we align PP to QQ using the optimal translation and scale.

Implementation Example

Consider an example in a two-dimensional space with corresponding points:

• Points in PP: (2,3)(2, 3), (3,4)(3, 4), (5,5)(5, 5) • Points in QQ: (4,6)(4, 6), (6,8)(6, 8), (10,10)(10, 10)

Step 1: Center the Data

• Centroid of PP: pˉ=(3.33,4)\bar{p} = (3.33, 4) • Centroid of QQ: qˉ=(6.67,8)\bar{q} = (6.67, 8)

Translate the points:

p1=(2,3)(3.33,4)=(1.33,1)p'_1 = (2, 3) - (3.33, 4) = (-1.33, -1)p2=(3,4)(3.33,4)=(0.33,0)p'_2 = (3, 4) - (3.33, 4) = (-0.33, 0)p3=(5,5)(3.33,4)=(1.67,1)p'_3 = (5, 5) - (3.33, 4) = (1.67, 1)

q1=(4,6)(6.67,8)=(2.67,2)q'_1 = (4, 6) - (6.67, 8) = (-2.67, -2)q2=(6,8)(6.67,8)=(0.67,0)q'_2 = (6, 8) - (6.67, 8) = (-0.67, 0)q3=(10,10)(6.67,8)=(3.33,2)q'_3 = (10, 10) - (6.67, 8) = (3.33, 2)

Step 2: Compute Scale

Calculate the scale ss:

s=(1.332.67+0.330.67+1.673.33)+(12+00+12)(1.332+0.332+1.672)+(12+02+12)s = \frac{(-1.33 \cdot -2.67 + -0.33 \cdot -0.67 + 1.67 \cdot 3.33) + (-1 \cdot -2 + 0 \cdot 0 + 1 \cdot 2)}{(-1.33^2 + -0.33^2 + 1.67^2) + (-1^2 + 0^2 + 1^2)}

Solving this gives s1.5s \approx 1.5.

Step 3: Compute Translation

Finally, compute the translation vector TT:

T=(6.67,8)1.5×(3.33,4)=(1.67,2)T = (6.67, 8) - 1.5 \times (3.33, 4) = (1.67, 2)

Summary Table

StepCalculationResult
Centroid of PPpi÷n\sum p_i \div n(3.33,4)(3.33, 4)
Centroid of QQqi÷n\sum q_i \div n(6.67,8)(6.67, 8)
Centered Pointspi=pipˉp'_i = p_i - \bar{p} qi=qiqˉq'_i = q_i - \bar{q}Translated coordinates
Scale ss$\frac\{\sum (p'_i \cdot q'_i)\}\{\sum |p'_i|^2\} $$1.5$
Translation TT$\bar\{q\} - s \bar\{p\}$$(1.67, 2)$

Conclusion

The approach of using least squares to determine the translation and scale for minimizing errors between two sets of points is both powerful and efficient in various practical applications. By centering, scaling, and translating the point sets, we can align them with minimized error, achieving optimal data fitting. This methodology provides a foundation for advanced transformations, extending its relevance to computer vision and geometric computing domains.


Course illustration
Course illustration

All Rights Reserved.