Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextureTransform.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Common/BIASpragmaStart.hh>
26 #include <Image/TextureTransform.hh>
27 
30  Matrix2x2<double>& Jac) const {
31  // numerical approximatioin of jacobian
32  // compute mapped points for 4-neighborhood
33  // this is actually a very good way for the jacobian approximation
34  // since we use is exactly for the step size which we assumed for
35  // computation
36 
37  HomgPoint2D sink_left, sink_right, sink_up, sink_down;
38  HomgPoint2D loc(src);
39  loc[0] -= 0.5;
40  if (MapForward(loc, sink_left)) return -1;
41  loc[0] += 1.0;
42  if (MapForward(loc, sink_right)) return -1;
43  loc[0] -= 0.5;
44  loc[1] -= 0.5;
45  if (MapForward(loc, sink_up)) return -1;
46  loc[1] += 1.0;
47  if (MapForward(loc, sink_down)) return -1;
48 
49  // difference vectors are rows of jacobian
50  Jac[0][0] = sink_right[0] - sink_left[0];
51  Jac[1][0] = sink_right[1] - sink_left[1];
52  Jac[0][1] = sink_down[0] - sink_up[0];
53  Jac[1][1] = sink_down[1] - sink_up[1];
54  return 0;
55 }
56 
59  Matrix2x2<double>& Jac) const {
60  // numerical approximatioin of jacobian
61  // compute mapped points for 4-neighborhood
62  // this is actually a very good way for the jacobian approximation
63  // since we use is exactly for the step size which we assumed for
64  // computation
65 
66  HomgPoint2D source_left, source_right, source_up, source_down;
67  HomgPoint2D locsink(sink);
68  locsink[0] -= 0.5;
69  if (MapBackward(locsink, source_left)) return -1;
70  locsink[0] += 1.0;
71  if (MapBackward(locsink, source_right)) return -1;
72  locsink[0] -= 0.5;
73  locsink[1] -= 0.5;
74  if (MapBackward(locsink, source_up)) return -1;
75  locsink[1] += 1.0;
76  if (MapBackward(locsink, source_down)) return -1;
77 
78  // difference vectors are rows of jacobian
79  Jac[0][0] = source_right[0] - source_left[0];
80  Jac[1][0] = source_right[1] - source_left[1];
81  Jac[0][1] = source_down[0] - source_up[0];
82  Jac[1][1] = source_down[1] - source_up[1];
83  return 0;
84 }
85 
88  // remember current parameters
90  GetParameters(p);
91  const unsigned int numvars = p.Size();
92  Jac.newsize(2,numvars);
93  HomgPoint2D p1, ref;
94  // map current point with current parameters
95  MapForward(src, ref);
96 
97  // vary each entry in p by 2%
98  for (unsigned int j=0; j<numvars; j++) {
99  Vector<double> pchanged(p);
100  double myeps = 0.02 * fabs(p[j]);
101  if (myeps<1e-9) myeps = 1e-9;
102  pchanged[j] += myeps;
103  // set the "new" parameters
104  SetParameters(pchanged);
105  // and map
106  MapForward(src, p1);
107  // compute difference and approximate jacobian entry
108  p1 -= ref;
109  Jac[0][j] = p1[0]/myeps;
110  Jac[1][j] = p1[0]/myeps;
111  }
112  // reset original parameters
113  SetParameters(p);
114  return 0;
115 }
116 
119  // remember current parameters
120  Vector<double> p;
121  GetParameters(p);
122  const unsigned int numvars = p.Size();
123  Jac.newsize(2, numvars);
124  HomgPoint2D p1, ref;
125  // map current point with current parameters
126  MapBackward(sink, ref);
127 
128  // vary each entry in p by 2%
129  for (unsigned int j=0; j<numvars; j++) {
130  Vector<double> pchanged(p);
131  double myeps = 0.02 * fabs(p[j]);
132  if (myeps<1e-9) myeps = 1e-9;
133  pchanged[j] += myeps;
134  // set the "new" parameters
135  SetParameters(pchanged);
136  // and map
137  MapBackward(sink, p1);
138  // compute difference and approximate jacobian entry
139  p1 -= ref;
140  Jac[0][j] = p1[0]/myeps;
141  Jac[1][j] = p1[0]/myeps;
142  }
143  // reset original parameters
144  SetParameters(p);
145  return 0;
146 }
147 
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
virtual int ParameterJacobianBackward(Matrix< double > &Jac, const HomgPoint2D &sink)
transformed position change when parameters change
Matrix< T > & newsize(Subscript M, Subscript N)
Definition: cmat.h:269
virtual int TextureJacobianForward(const HomgPoint2D &src, Matrix2x2< double > &Jac) const
shape change of the local region when mapping forward
virtual int ParameterJacobianForward(Matrix< double > &Jac, const HomgPoint2D &src)
transformed position change when parameters change
unsigned int Size() const
length of the vector
Definition: Vector.hh:143
virtual int MapForward(const HomgPoint2D &src, HomgPoint2D &sink) const =0
map a point in image &quot;source&quot; to a point in image &quot;sink&quot;
virtual int TextureJacobianBackward(const HomgPoint2D &sink, Matrix2x2< double > &Jac) const
shape change of the local region when mapping backward