digiKam
pointtransformaffine.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 16/08/2016
7  * Description : point transform class and its utilities that models
8  * affine transformations between two sets of 2d-points.
9  *
10  * Copyright (C) 2016 by Omar Amin <Omar dot moh dot amin at gmail dot com>
11  * Copyright (C) 2016-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_POINT_TRANSFORM_AFFINE_H
27 #define DIGIKAM_POINT_TRANSFORM_AFFINE_H
28 
29 // C++ includes
30 
31 #include <vector>
32 #include <iostream>
33 
34 // Local includes
35 
36 #include "matrixoperations.h"
37 #include "vectoroperations.h"
38 
39 namespace Digikam
40 {
41 
43 {
44 public:
45 
47  PointTransformAffine(const std::vector<std::vector<float> >& m_,
48  const std::vector<float>& b_);
49  explicit PointTransformAffine(const std::vector<std::vector<float> >& m_);
50 
51  const std::vector<float> operator() (const std::vector<float>& p) const;
52 
53  const std::vector<std::vector<float> >& get_m() const;
54  const std::vector<float>& get_b() const;
55 
56 private:
57 
58  std::vector<std::vector<float> > m;
59  std::vector<float> b;
60 };
61 
62 // ----------------------------------------------------------------------------------------
63 
65  const PointTransformAffine& rhs);
66 
67 // ----------------------------------------------------------------------------------------
68 
70 
71 // ----------------------------------------------------------------------------------------
72 
73 template <typename T>
74 PointTransformAffine findAffineTransform(const std::vector<std::vector<T> >& fromPoints,
75  const std::vector<std::vector<T> >& toPoints)
76 {
77  std::vector<std::vector<float> > P(3, std::vector<float>(fromPoints.size()));
78  std::vector<std::vector<float> > Q(2, std::vector<float>(fromPoints.size()));
79 
80  for (unsigned long i = 0 ; i < fromPoints.size() ; ++i)
81  {
82  P[0][i] = fromPoints[i][0];
83  P[1][i] = fromPoints[i][1];
84  P[2][i] = 1;
85 
86  Q[0][i] = toPoints[i][0];
87  Q[1][i] = toPoints[i][1];
88  }
89 
90  const std::vector<std::vector<float> > m = Q * MatrixOperations::pinv(P);
91 
92  return PointTransformAffine(m);
93 }
94 
95 // ----------------------------------------------------------------------------------------
96 
97 PointTransformAffine findSimilarityTransform(const std::vector<std::vector<float> >& fromPoints,
98  const std::vector<std::vector<float> >& toPoints);
99 
100 } // namespace Digikam
101 
102 #endif // DIGIKAM_POINT_TRANSFORM_AFFINE_H
Definition: pointtransformaffine.h:43
const std::vector< float > & get_b() const
Definition: pointtransformaffine.cpp:79
PointTransformAffine()
Definition: pointtransformaffine.cpp:32
const std::vector< std::vector< float > > & get_m() const
Definition: pointtransformaffine.cpp:74
const std::vector< float > operator()(const std::vector< float > &p) const
Definition: pointtransformaffine.cpp:68
std::vector< std::vector< float > > pinv(const std::vector< std::vector< float > > &mat)
Definition: matrixoperations.cpp:58
Definition: datefolderview.cpp:43
PointTransformAffine inv(const PointTransformAffine &trans)
Definition: pointtransformaffine.cpp:95
PointTransformAffine operator*(const PointTransformAffine &lhs, const PointTransformAffine &rhs)
Definition: pointtransformaffine.cpp:86
PointTransformAffine findSimilarityTransform(const std::vector< std::vector< float > > &fromPoints, const std::vector< std::vector< float > > &toPoints)
Definition: pointtransformaffine.cpp:104
PointTransformAffine findAffineTransform(const std::vector< std::vector< T > > &fromPoints, const std::vector< std::vector< T > > &toPoints)
Definition: pointtransformaffine.h:74