slmsuite.holography.analysis.fit_affine#

fit_affine(x, y, guess_affine=None, plot=False)[source]#

For two sets of ordered points with equal length, find the best-fit affine transformation that transforms from the first basis to the second. Best fit is defined as minimization on the least squares euclidean norm.

\[\vec{y} = M \cdot \vec{x} + \vec{b}\]
Parameters:
  • x (array_like) – Array of vectors of shape (2, N) in the style of format_2vectors().

  • y (array_like) – Array of vectors of shape (2, N) in the style of format_2vectors().

  • guess_affine (dict OR None) – The user may provide a guess to immediately proceed with least squares fitting. This guess must be in the form of a dictionary with fields "M" and "b". If None, a guess is computed based on centroiding and moment matching.

  • plot (bool) – Whether to produce a debug plot.

Returns:

A dictionary with fields "M" and "b".

Return type:

dict