Blender  V3.3
conditioning.cc
Go to the documentation of this file.
1 // Copyright (c) 2010 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
23 
24 namespace libmv {
25 
26 // HZ 4.4.4 pag.109: Point conditioning (non isotropic)
27 void PreconditionerFromPoints(const Mat& points, Mat3* T) {
28  Vec mean, variance;
29  MeanAndVarianceAlongRows(points, &mean, &variance);
30 
31  double xfactor = sqrt(2.0 / variance(0));
32  double yfactor = sqrt(2.0 / variance(1));
33 
34  // If variance is equal to 0.0 set scaling factor to identity.
35  // -> Else it will provide nan value (because division by 0).
36  if (variance(0) < 1e-8)
37  xfactor = mean(0) = 1.0;
38  if (variance(1) < 1e-8)
39  yfactor = mean(1) = 1.0;
40 
41  // clang-format off
42  *T << xfactor, 0, -xfactor * mean(0),
43  0, yfactor, -yfactor * mean(1),
44  0, 0, 1;
45  // clang-format on
46 }
47 // HZ 4.4.4 pag.107: Point conditioning (isotropic)
49  Vec mean, variance;
50  MeanAndVarianceAlongRows(points, &mean, &variance);
51 
52  double var_norm = variance.norm();
53  double factor = sqrt(2.0 / var_norm);
54 
55  // If variance is equal to 0.0 set scaling factor to identity.
56  // -> Else it will provide nan value (because division by 0).
57  if (var_norm < 1e-8) {
58  factor = 1.0;
59  mean.setOnes();
60  }
61 
62  // clang-format off
63  *T << factor, 0, -factor * mean(0),
64  0, factor, -factor * mean(1),
65  0, 0, 1;
66  // clang-format on
67 }
68 
69 void ApplyTransformationToPoints(const Mat& points,
70  const Mat3& T,
71  Mat* transformed_points) {
72  int n = points.cols();
73  transformed_points->resize(2, n);
74  Mat3X p(3, n);
75  EuclideanToHomogeneous(points, &p);
76  p = T * p;
77  HomogeneousToEuclidean(p, transformed_points);
78 }
79 
80 void NormalizePoints(const Mat& points, Mat* normalized_points, Mat3* T) {
81  PreconditionerFromPoints(points, T);
82  ApplyTransformationToPoints(points, *T, normalized_points);
83 }
84 
85 void NormalizeIsotropicPoints(const Mat& points,
86  Mat* normalized_points,
87  Mat3* T) {
89  ApplyTransformationToPoints(points, *T, normalized_points);
90 }
91 
92 // Denormalize the results. See HZ page 109.
93 void UnnormalizerT::Unnormalize(const Mat3& T1, const Mat3& T2, Mat3* H) {
94  *H = T2.transpose() * (*H) * T1;
95 }
96 
97 void UnnormalizerI::Unnormalize(const Mat3& T1, const Mat3& T2, Mat3* H) {
98  *H = T2.inverse() * (*H) * T1;
99 }
100 
101 } // namespace libmv
sqrt(x)+1/max(0
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
#define T
#define T2
Definition: md5.cpp:18
#define T1
Definition: md5.cpp:17
#define H(x, y, z)
Eigen::VectorXd Vec
Definition: numeric.h:61
void NormalizePoints(const Mat &points, Mat *normalized_points, Mat3 *T)
Definition: conditioning.cc:80
void EuclideanToHomogeneous(const Mat &X, Mat *H)
Definition: projection.cc:200
void PreconditionerFromPoints(const Mat &points, Mat3 *T)
Definition: conditioning.cc:27
Eigen::Matrix< double, 3, 3 > Mat3
Definition: numeric.h:72
void HomogeneousToEuclidean(const Mat &H, Mat *X)
Definition: projection.cc:166
Eigen::MatrixXd Mat
Definition: numeric.h:60
void MeanAndVarianceAlongRows(const Mat &A, Vec *mean_pointer, Vec *variance_pointer)
Definition: numeric.cc:90
void NormalizeIsotropicPoints(const Mat &points, Mat *normalized_points, Mat3 *T)
Definition: conditioning.cc:85
void ApplyTransformationToPoints(const Mat &points, const Mat3 &T, Mat *transformed_points)
Definition: conditioning.cc:69
Eigen::Matrix< double, 3, Eigen::Dynamic > Mat3X
Definition: numeric.h:92
void IsotropicPreconditionerFromPoints(const Mat &points, Mat3 *T)
Definition: conditioning.cc:48
static void Unnormalize(const Mat3 &T1, const Mat3 &T2, Mat3 *H)
Definition: conditioning.cc:97
static void Unnormalize(const Mat3 &T1, const Mat3 &T2, Mat3 *H)
Definition: conditioning.cc:93