PIXELBANKv9.1.0
Menu

Implement a function to estimate the optimal translation that aligns two point sets with known correspondences. This problem is rooted in Least Squares Alignment, a fundamental concept in Image Alignment and Stitching, where the goal is to find the best transformation that minimizes the distance between two sets of points.

The translation vector that achieves this alignment can be found by considering the centroids of the source and target point sets, which are the average positions of all points in each set. The optimal translation is the vector that moves the centroid of the source to the centroid of the target.

Here are the steps to estimate the translation:

  1. Compute the centroid of the source point set.
  2. Compute the centroid of the target point set.
  3. Calculate the translation vector as the difference between the target and source centroids.
t=qˉ−pˉ\mathbf{t} = \bar{\mathbf{q}} - \bar{\mathbf{p}}

This technique is widely used in computer vision applications, such as image registration and object tracking.

Example:

Input:
source = [(0, 0), (1, 0)]
target = [(5, 5), (6, 5)]
Output:
(5.0, 5.0)
Reasoning:
  1. Compute source centroid:

    • xÌ„_src = (0 + 1) / 2 = 0.5
    • ȳ_src = (0 + 0) / 2 = 0.0
    • Centroid_src = (0.5, 0.0)
  2. Compute target centroid:

    • xÌ„_tgt = (5 + 6) / 2 = 5.5
    • ȳ_tgt = (5 + 5) / 2 = 5.0
    • Centroid_tgt = (5.5, 5.0)
  3. Translation = target_centroid - source_centroid:

    • tx = 5.5 - 0.5 = 5.0
    • ty = 5.0 - 0.0 = 5.0

Translation (5, 5) moves the source pattern to match the target.

Constraints:

  • source and target are lists of corresponding (x, y) points
  • Return translation as (tx, ty) tuple
  • Round 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.
Estimate Translation - Easy | PixelBank