25 #ifndef __TextureTransformSimilar__hh__
26 #define __TextureTransformSimilar__hh__
28 #include <Base/Common/BIASpragmaStart.hh>
29 #include <Image/TextureTransform.hh>
30 #include <Base/Common/CompareFloatingPoint.hh>
53 const double& sx = src[0];
54 const double& sy = src[1];
55 sink[0] =
A_[0][0]*sx +
A_[0][1]*sy +
tx_;
56 sink[1] =
A_[1][0]*sx +
A_[1][1]*sy +
ty_;
68 if (!
Equal(testsink[0]+1e-4,sink[0]+1e-4, 1e-4) ||
69 !
Equal(testsink[1]+1e-4,sink[1]+1e-4, 1e-4)) {
70 BIASERR(testsink<<
" and "<<sink<<
" are not equal!!!");
95 const double sinphi = sin(
P_[0]);
96 const double cosphi = cos(
P_[0]);
97 const double scale =
P_[1];
98 const double scaleplus1 = scale+1.0;
99 const double x = src[0]-
origin_[0];
100 const double y = src[1]-origin_[1];
102 Jac[0][0] = -sinphi*scaleplus1*x-cosphi*scaleplus1*y;
103 Jac[0][1] = cosphi*x-sinphi*y;
107 Jac[1][0] = cosphi*scaleplus1*x-sinphi*scaleplus1*y;
108 Jac[1][1] = sinphi*x+cosphi*y;
117 const double sinphi = sin(
P_[0]);
118 const double cosphi = cos(
P_[0]);
119 const double scale =
P_[1];
120 const double scaleplus1 = scale+1.0;
121 const double c13 =
P_[2];
122 const double c23 =
P_[3];
123 const double x = src[0]-
origin_[0];
124 const double y = src[1]-origin_[1];
126 Jac[0][0] = (-sinphi*x+cosphi*y-cosphi*c23+c13*sinphi)/scaleplus1;
127 Jac[0][1] = (-cosphi*x-sinphi*y+sinphi*c23+c13*cosphi)/
128 (scaleplus1*scaleplus1);
129 Jac[0][2] = -cosphi/scaleplus1;
130 Jac[0][3] = -sinphi/scaleplus1;
133 Jac[1][0] = (-cosphi*x-sinphi*y+sinphi*c23+c13*cosphi)/scaleplus1;
134 Jac[1][1] = -(-sinphi*x+cosphi*y-cosphi*c23+c13*sinphi)/
135 (scaleplus1*scaleplus1);
136 Jac[1][2] = sinphi/scaleplus1;
137 Jac[1][3] = -cosphi/scaleplus1;
151 BIASASSERT(p.
Size()==4);
153 A_[0][0] =
A_[1][1] = cos(p[0])*(p[1]+1.0);
154 A_[0][1] = -sin(p[0])*(p[1]+1.0);
155 A_[1][0] = -
A_[0][1];
159 tx_ = p[2]-offset[0];
160 ty_ = p[3]-offset[1];
177 A2[0][0] = A2[1][1] = cos(deltaP[0])*(deltaP[1]+1.0);
178 A2[0][1] = -sin(deltaP[0])*(deltaP[1]+1.0);
179 A2[1][0] = -A2[0][1];
182 A2[0][2] = deltaP[2]-(A2[0][0]-1.0)*
origin_[0]-A2[0][1]*
origin_[1];
183 A2[1][2] = deltaP[3]-A2[1][0]*origin_[0]-(A2[1][1]-1.0)*origin_[1];
189 p[1] = sqrt(A1.GetDeterminant());
190 const double sine = (A1[1][0]-A1[0][1])/(2.0*p[1]);
191 const double cosine = (A1[0][0]+A1[1][1])/(2.0*p[1]);
192 p[0] = atan2(sine, cosine);
194 p[2] = A1[0][2] + (A1[0][0]-1.0)*origin_[0] + A1[0][1]*origin_[1];
195 p[3] = A1[1][2] + A1[1][0]*origin_[0] + (A1[1][1]-1.0)*origin_[1];
virtual bool TextureJacobianIsConstant() const
local warp is the same at any image position
int Invert(Matrix2x2< T > &result) const
analyticaly inverts matrix
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
int ParameterJacobianBackward(Matrix< double > &Jac, const HomgPoint2D &src)
transformed position change when parameters change
void ComposeWithInverseDeltaP(const Vector< double > &deltaP)
concatenate *this and an inverse transform with param deltaP and save new parameter vector to *this...
Vector< double > P_
current set of parameters, see SetParameters for meaning
Matrix< T > & newsize(Subscript M, Subscript N)
class for representing parameterized image warps, such as homography, displacement, ...
unsigned int Size() const
length of the vector
void SetParameters(const Vector< double > &p)
rotation(rad), scale-1, dx,dy.
Vector< T > & newsize(Subscript N)
int ParameterJacobianForward(Matrix< double > &Jac, const HomgPoint2D &src)
transformed position change when parameters change
int GetInverse(Matrix3x3< T > &inv) const
Matrix inversion: inverts this and stores resulty in argument inv.
Vector2< double > origin_
origin relative to which rotation and scale is performed
Matrix2x2< double > A_
cached local warp and inverse
int TextureJacobianBackward(const HomgPoint2D &sink, Matrix2x2< double > &Jac) const
shape change of the local region when mapping backward
TextureTransformSimilar()
virtual ~TextureTransformSimilar()
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
const Vector2< double > & GetOrigin() const
origin relative to which rotation and scale is performed
int MapForward(const HomgPoint2D &src, HomgPoint2D &sink) const
map a point in image "source" to a point in image "sink"
void SetOrigin(const Vector2< double > &origin)
origin relative to which rotation and scale is performed
double tx_
cached displacement and inverse
Matrix2x2< double > Ainv_
int MapBackward(const HomgPoint2D &sink, HomgPoint2D &src) const
map a point in image "source" to a point in image "sink"
bool ParameterJacobianIsConstant() const
the jacobian depends on x
virtual TextureTransformSimilar * Clone() const
virtual covariant copy constructor, caller must eventually destroy the created object ...
int TextureJacobianForward(const HomgPoint2D &src, Matrix2x2< double > &Jac) const
shape change of the local region when mapping forward