Blender V4.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
24namespace libmv {
25
26// HZ 4.4.4 pag.109: Point conditioning (non isotropic)
27void 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 }
39 if (variance(1) < 1e-8) {
40 yfactor = mean(1) = 1.0;
41 }
42
43 // clang-format off
44 *T << xfactor, 0, -xfactor * mean(0),
45 0, yfactor, -yfactor * mean(1),
46 0, 0, 1;
47 // clang-format on
48}
49// HZ 4.4.4 pag.107: Point conditioning (isotropic)
51 Vec mean, variance;
52 MeanAndVarianceAlongRows(points, &mean, &variance);
53
54 double var_norm = variance.norm();
55 double factor = sqrt(2.0 / var_norm);
56
57 // If variance is equal to 0.0 set scaling factor to identity.
58 // -> Else it will provide nan value (because division by 0).
59 if (var_norm < 1e-8) {
60 factor = 1.0;
61 mean.setOnes();
62 }
63
64 // clang-format off
65 *T << factor, 0, -factor * mean(0),
66 0, factor, -factor * mean(1),
67 0, 0, 1;
68 // clang-format on
69}
70
72 const Mat3& T,
73 Mat* transformed_points) {
74 int n = points.cols();
75 transformed_points->resize(2, n);
76 Mat3X p(3, n);
77 EuclideanToHomogeneous(points, &p);
78 p = T * p;
79 HomogeneousToEuclidean(p, transformed_points);
80}
81
82void NormalizePoints(const Mat& points, Mat* normalized_points, Mat3* T) {
83 PreconditionerFromPoints(points, T);
84 ApplyTransformationToPoints(points, *T, normalized_points);
85}
86
87void NormalizeIsotropicPoints(const Mat& points,
88 Mat* normalized_points,
89 Mat3* T) {
91 ApplyTransformationToPoints(points, *T, normalized_points);
92}
93
94// Denormalize the results. See HZ page 109.
95void UnnormalizerT::Unnormalize(const Mat3& T1, const Mat3& T2, Mat3* H) {
96 *H = T2.transpose() * (*H) * T1;
97}
98
99void UnnormalizerI::Unnormalize(const Mat3& T1, const Mat3& T2, Mat3* H) {
100 *H = T2.inverse() * (*H) * T1;
101}
102
103} // namespace libmv
sqrt(x)+1/max(0
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
#define T2
Definition md5.cpp:19
#define T1
Definition md5.cpp:18
#define H(x, y, z)
Eigen::VectorXd Vec
Definition numeric.h:61
void NormalizePoints(const Mat &points, Mat *normalized_points, Mat3 *T)
void EuclideanToHomogeneous(const Mat &X, Mat *H)
void PreconditionerFromPoints(const Mat &points, Mat3 *T)
Eigen::Matrix< double, 3, 3 > Mat3
Definition numeric.h:72
void HomogeneousToEuclidean(const Mat &H, Mat *X)
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)
void ApplyTransformationToPoints(const Mat &points, const Mat3 &T, Mat *transformed_points)
Eigen::Matrix< double, 3, Eigen::Dynamic > Mat3X
Definition numeric.h:92
void IsotropicPreconditionerFromPoints(const Mat &points, Mat3 *T)
static void Unnormalize(const Mat3 &T1, const Mat3 &T2, Mat3 *H)
static void Unnormalize(const Mat3 &T1, const Mat3 &T2, Mat3 *H)