vampire.processing.align_contour#

vampire.processing.align_contour(contour, mean_contour)[source]#

Aligns one contour to the mean of the set of contours.

Parameters:
contourndarray

x and y coordinates of object contour, with shape (2, n).

mean_contourndarray

Mean contour coordinates of the set of contours, with shape (2, n).

Returns:
aligned_contourndarray

Aligned contour closest to the mean contour, with shape (2, n).

See also

vampire.amath.get_rotation_matrix

Find rotation matrix by Kabsch algorithm.

Notes

Defining the contours

Suppose we have \(N\) pairs of mean-subtracted \(x\) and \(y\) coordinates of the \(i\) th object contour stored in row vectors \(\mathbf{x}\) and \(\mathbf{y}\). We define the coordinate matrix

\[\begin{split}\mathbf{A}_i = \begin{bmatrix} — & \mathbf{x}_i & — \\ — & \mathbf{y}_i & — \\ \end{bmatrix}.\end{split}\]

The average object contour have coordinates \(\mathbf{\bar{x}}\) and \(\mathbf{\bar{y}}\), obtained from averaging the coordinates of corresponding points from each object. We define the average coordinate matrix

\[\begin{split}\mathbf{\bar{A}} = \begin{bmatrix} — & \mathbf{\bar{x}} & — \\ — & \mathbf{\bar{y}} & — \\ \end{bmatrix}.\end{split}\]

Finding the optimal rotation matrix

We can find the optimal rotation matrix \(\mathbf{R}\) using the Kabsch algorithm (implemented in get_rotation_matrix).

Applying the optimal rotation matrix

The rotated contour \(\mathbf{A}_i'\) aligned with the average object contour is then

\[\mathbf{A}_i' = \mathbf{RA}_i\]