IMP logo
IMP Reference Guide  develop.d36d3deffb,2026/11/09
The Integrative Modeling Platform
align2D.h
Go to the documentation of this file.
1 /*!
2  * \file IMP/em2d/align2D.h
3  * \brief Alignment of images in 2D
4  * Copyright 2007-2026 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPEM2D_ALIGN_2D_H
8 #define IMPEM2D_ALIGN_2D_H
9 
10 #include <IMP/em2d/em2d_config.h>
12 #include "IMP/algebra/utility.h"
14 #include "IMP/algebra/Vector2D.h"
15 #include <algorithm>
16 #include <vector>
17 
18 IMPEM2D_BEGIN_NAMESPACE
19 
20 //! Definition of the result of an alignment. Contains the transformation
21 //! to apply to the matrix to align and the cross correlation of the solution
22 typedef std::pair<algebra::Transformation2D, double> ResultAlign2D;
23 
24 //! Aligns completely two matrices (rotationally and translationally).
25 //! Uses the autocorrelation function to speed up the rotational alignment
26 /*!
27  \param[in] input Reference matrix
28  \param[in] m_to_align Matrix to align to the reference
29  \param[in] apply if true, apply the transformation
30  to m_to_align after alignment
31  \return The result. Check the definition of ResultAlign2D
32 */
33 IMPEM2DEXPORT ResultAlign2D get_complete_alignment(const DoubleMatrix &input,
34  DoubleMatrix &m_to_align,
35  bool apply = false);
36 
37 //! Aligns two matrices rotationally. Based on the autocorrelation function
38 //! of the matrices.
39 /*!
40  \param[in] input Reference matrix
41  \param[in] m_to_align Matrix to align to the reference
42  \param[in] apply if true, apply the transformation
43  to m_to_align after alignment
44  \return The result. Check the definition of ResultAlign2D
45 */
47  const DoubleMatrix &input, DoubleMatrix &m_to_align, bool apply = false);
48 
49 //! Aligns two matrices translationally
50 /*!
51  \param[in] input Reference matrix
52  \param[in] m_to_align Matrix to align to the reference
53  \param[in] apply if true, apply the transformation
54  to m_to_align after alignment
55  \return The result. Check the definition of ResultAlign2D
56 */
58  const DoubleMatrix &input, DoubleMatrix &m_to_align, bool apply = false);
59 
60 //! Aligns two matrices rotationally and translationally without
61 //! performing preprocessing. Preprocessed data must be provided.
62 /*!
63  \param[in] input first matrix
64  \param[in] INPUT fft of the first matrix
65  \param[in] POLAR1 fft of the autocorrelation (in polars) of the input.
66  \param[in] m_to_align the matrix to align with the input
67  \param[in] POLAR2 fft of the autocorrelation (in polars) of m_to_align
68  \param[in] apply true if m_to_align is transformed at the end
69  \return The result. Check the definition of ResultAlign2D
70 */
72  const DoubleMatrix &input, const DoubleMatrix &INPUT,
73  const DoubleMatrix &POLAR1, DoubleMatrix &m_to_align,
74  const DoubleMatrix &POLAR2, bool apply = false);
75 
76 //! Computes the rotational alignment for two autocorrelation matrices
77 //! It is assumed that the arguments are FFTs
78 /*!
79  \param[in] POLAR1 fft of the first autocorrelation (in polars)
80  \param[in] POLAR2 fft of the second autocorrelation (in polars)
81  \return The result. Check the definition of ResultAlign2D
82 */
83 IMPEM2DEXPORT ResultAlign2D
85  const DoubleMatrix &POLAR2);
86 
87 //! Aligns two matrices translationally without preprocessing. The preprocessed
88 //! data must be provided.
89 /*!
90  \param[in] M1 the dft the first matrix (input)
91  \param[in] M2 the dft of the matrix to align with the input
92  \return The result. Check the definition of ResultAlign2D
93 */
94 IMPEM2DEXPORT ResultAlign2D
96  const DoubleMatrix &M2);
97 
98 //! Aligns two matrices (rotation and translation) using centers and
99 //! no preprocessing. Preprocessed data must be provided.
100 /*!
101  \param[in] center1 weighted centroid of the reference matrix
102  \param[in] center2 weighted centroid of the matrix to align
103  \param[in] AUTOC_POLAR1 fft of the autocorrelation (in polars) of the input.
104  \param[in] AUTOC_POLAR2 fft of the autocorrelation (in polars) of m_to_align
105  \return The result. Check the definition of ResultAlign2D
106 */
107 IMPEM2DEXPORT ResultAlign2D
109  const algebra::Vector2D &center1, const algebra::Vector2D &center2,
110  const DoubleMatrix &AUTOC_POLAR1, const DoubleMatrix &AUTOC_POLAR2);
111 
112 IMPEM2D_END_NAMESPACE
113 
114 #endif /* IMPEM2D_ALIGN_2D_H */
ResultAlign2D get_translational_alignment(const DoubleMatrix &input, DoubleMatrix &m_to_align, bool apply=false)
Aligns two matrices translationally.
VectorD< 2 > Vector2D
Definition: VectorD.h:403
Simple 2D vector class.
2D transformations. Copyright 2007-2026 IMP Inventors. All rights reserved.
Functions to deal with very common math operations.
ResultAlign2D get_complete_alignment_with_centers_no_preprocessing(const algebra::Vector2D &center1, const algebra::Vector2D &center2, const DoubleMatrix &AUTOC_POLAR1, const DoubleMatrix &AUTOC_POLAR2)
em2d::ResultAlign2D get_rotational_alignment(const DoubleMatrix &input, DoubleMatrix &m_to_align, bool apply=false)
Functions related with rotations in em2d Copyright 2007-2026 IMP Inventors. All rights reserved...
std::pair< algebra::Transformation2D, double > ResultAlign2D
Definition: align2D.h:22
ResultAlign2D get_translational_alignment_no_preprocessing(const DoubleMatrix &M1, const DoubleMatrix &M2)
ResultAlign2D get_complete_alignment(const DoubleMatrix &input, DoubleMatrix &m_to_align, bool apply=false)
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > DoubleMatrix
Matrix of doubles, used to store the data of an image.
Definition: Matrix.h:28
ResultAlign2D get_rotational_alignment_no_preprocessing(const DoubleMatrix &POLAR1, const DoubleMatrix &POLAR2)
em2d::ResultAlign2D get_complete_alignment_no_preprocessing(const DoubleMatrix &input, const DoubleMatrix &INPUT, const DoubleMatrix &POLAR1, DoubleMatrix &m_to_align, const DoubleMatrix &POLAR2, bool apply=false)