1 #include "Geometry/LocalAffineFrame.hh"
2 #include "Base/ImageUtils/ImageDraw.hh"
3 #include "Base/Image/ColourRGB.hh"
4 #include "Geometry/HMatrix.hh"
11 os <<
" "<< fp.
t_<<
" " << fp.
A_ << endl;
18 BIASASSERT(is.good());
25 double& Version)
const {
26 TopLevelTag =
"LocalAffineFrame";
32 XMLIO& XMLObject)
const {
34 BIASERR(
"not yet implemented");
40 BIASERR(
"not yet implemented");
48 const double& positionCovScale,
49 const unsigned int linethickness)
const {
53 double center[2]={t_[0], t_[1]}, a[2], b[2];
64 a[0] = phi[0][0] * eva;
65 a[1] = phi[1][0] * eva;
66 b[0] = phi[0][1] * evb;
67 b[1] = phi[1][1] * evb;
68 unsigned char value[]={127, 255, 0};
73 oriLine = A_ * oriLine;
75 (
int)rint(center[1])) &&
77 (
int)rint(oriLine[0]),
78 (
int)rint(center[1]) +
79 (
int)rint(oriLine[1]))) {
82 (
int)rint(center[0]), (
int)rint(center[1]),
83 (
int)rint(center[0])+ (
int)rint(oriLine[0]),
84 (
int)rint(center[1]) + (
int)rint(oriLine[1]));
89 if (positionCovScale>0.0) {
90 double a[2], b[2], eva, evb;
92 double center[2]={t_[0], t_[1]};
93 unsigned char col[]={255, 0, 0};
95 for (
unsigned int i=0; i<2; i++) {
96 for (
unsigned int j=0; j<2; j++) {
97 curcov[i][j] = Cov_[4+i][4+j];
105 a[0] = na[0] * eva * positionCovScale;
106 a[1] = na[1] * eva * positionCovScale;
107 b[0] = nb[0] * evb * positionCovScale;
108 b[1] = nb[1] * evb * positionCovScale;
130 for (
unsigned int i=0; i<6; i++) {
131 for (
unsigned int j=i; j<6; j++) {
132 covbc[i][j] = covbc[j][i] = 0.5 * (Cov_[j][i]+Cov_[i][j]);
133 covbc[i+6][j+6] = covbc[j+6][i+6] = 0.5 * (F2.
Cov_[j][i]+F2.
Cov_[i][j]);
137 const double b11=A_[0][0], b12=A_[0][1], b21=A_[1][0], b22=A_[1][1];
138 const double c11=F2.
A_[0][0], c12=F2.
A_[0][1], c21=F2.
A_[1][0],
139 c22=F2.
A_[1][1], c13=F2.
t_[0], c23=F2.
t_[1];
141 const double detc = c11*c22-c21*c12;
146 dadbc[0][0] = c22/detc;
147 dadbc[0][1] = -c21/detc;
148 dadbc[1][0] = -c12/detc;
149 dadbc[1][1] = c11/detc;
150 dadbc[4][0] = (c12*c23-c22*c13)/detc;
151 dadbc[4][1] = (c21*c13-c11*c23)/detc;
154 dadbc[2][2] = c22/detc;
155 dadbc[2][3] = -c21/detc;
156 dadbc[3][2] = -c12/detc;
157 dadbc[3][3] = c11/detc;
158 dadbc[5][2] = (c12*c23-c22*c13)/detc;
159 dadbc[5][3] = (c21*c13-c11*c23)/detc;
162 const double detc2 = detc*detc;
164 dadbc[0][6] = -c22*(b11*c22-b12*c21)/detc2;
165 dadbc[1][6] = (b12*detc-c22*(b12*c11-b11*c12))/detc2;
166 dadbc[4][6] = (-c23*b12*detc-c22*(b11*(c12*c23-c22*c13) +
167 b12*(c21*c13-c11*c23)))/detc2;
168 dadbc[2][6] = -c22*(b21*c22-b22*c21)/detc2;
169 dadbc[3][6] = (b22*detc-c22*(b22*c11-b21*c12))/detc2;
170 dadbc[5][6] = (-c23*b22*detc-c22*(b21*(c12*c23-c22*c13) +
171 b22*(c21*c13-c11*c23)))/detc2;
174 dadbc[0][7] = c21*(b11*c22-b12*c21)/detc2;
175 dadbc[1][7] = (-b11*detc+c21*(b12*c11-b11*c12))/detc2;
176 dadbc[4][7] = (c23*b11*detc+c21*(b11*(c12*c23-c22*c13)+
177 b12*(c21*c13-c11*c23)))/detc2;
178 dadbc[2][7] = c21*(b21*c22-b22*c21)/detc2;
179 dadbc[3][7] = (-b21*detc+c21*(b22*c11-b21*c12))/detc2;
180 dadbc[5][7] = (c23*b21*detc+c21*(b21*(c12*c23-c22*c13)+
181 b22*(c21*c13-c11*c23)))/detc2;
184 dadbc[4][10] = (b12*c21-c22*b11)/detc;
185 dadbc[5][10] = (b22*c21-c22*b21)/detc;
188 dadbc[0][8] = (c12*(b11*c22-b12*c21)-b21*detc)/detc2;
189 dadbc[1][8] = c12*(b12*c11-b11*c12)/detc2;
190 dadbc[4][8] = (b12*c13*detc+c12*(b11*(c12*c23-c22*c13)+
191 b12*(c21*c13-c11*c23)))/detc2;
192 dadbc[2][8] = (c12*(b21*c22-b22*c21)-b22*detc)/detc2;
193 dadbc[3][8] = c12*(b22*c11-b21*c12)/detc2;
194 dadbc[5][8] = (b22*c13*detc+c12*(b21*(c12*c23-c22*c13)+
195 b22*(c21*c13-c11*c23)))/detc2;
198 dadbc[0][9]= (-c11*(b11*c22-b12*c21)+b11*detc)/detc2;
199 dadbc[1][9]= c11*(b12*c11-b11*c12)/detc2;
200 dadbc[4][9]= (-b11*c13*detc-c11*(b11*(c12*c23-c22*c13)+
201 b12*(c21*c13-c11*c23)))/detc2;
202 dadbc[2][9]= (-c11*(b21*c22-b22*c21)+b21*detc)/detc2;
203 dadbc[3][9]= c11*(b22*c11-b21*c12)/detc2;
204 dadbc[5][9]= (-b21*c13*detc-c11*(b21*(c12*c23-c22*c13)+
205 b22*(c21*c13-c11*c23)))/detc2;
208 dadbc[4][11]= (b11*c12-b12*c11)/detc;
209 dadbc[5][11]= (b21*c12-b22*c11)/detc;
215 return relativeTransform;
228 affineTransformer[1][1] = affineTransformer[0][0] = jac[0][0];
229 affineTransformer[3][3] = affineTransformer[2][2] = jac[1][1];
230 affineTransformer[2][0] = affineTransformer[3][1] = jac[1][0];
231 affineTransformer[0][2] = affineTransformer[1][3] = jac[0][1];
232 affineTransformer[4][4] = jac[0][0];
233 affineTransformer[4][5] = jac[0][1];
234 affineTransformer[5][4] = jac[1][0];
235 affineTransformer[5][5] = jac[1][1];
240 affineparams = affineTransformer * affineparams;
242 affineparams[4] = x[0];
243 affineparams[5] = x[1];
247 cov = affineTransformer * Cov_ * affineTransformer.
Transpose();
269 tammat[0][0] = xy[0];
270 tammat[0][1] = xy[1];
271 tammat[1][0] = -xy[1];
272 tammat[1][1] = xy[0];
int Invert(Matrix2x2< T > &result) const
analyticaly inverts matrix
LocalAffineFrame GetRelativeTransform(const LocalAffineFrame &F2, bool setDefaultCov=false) const
get global transform to transfer an image point of 1 into the image system of 2, e.g.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
BIAS::Vector2< double > t_
original image position
a 3x3 Matrix describing projective transformations between planes
Matrix< T > Transpose() const
transpose function, storing data destination matrix
BIAS::LocalAffineFrame GetLocalSimilarityFrame() const
find closest scaled rotation matrix to linear A (under Frobenius norm) and return ...
affine transformation of 2D image plane which relates image coordinate system and local affine featur...
bool IsPositionInImage(const int &x, const int &y) const
check if image contains that pixel position
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
static int FactorizeAffineMatrixRRight(const Matrix2x2< double > &A, Matrix2x2< double > &phi, Matrix2x2< double > &theta, double &d1, double &d2)
decompose affine matrix into rotations and nonisotropic scalings
void GetJacobian(const HomgPoint2D &x, Matrix< double > &Jac) const
returns jacobian of H: R^2 –> R^2
void SetA(const BIAS::Matrix2x2< double > &A, const BIAS::Matrix< double > &cov=BIAS::Matrix< double >(4, 4, BIAS::MatrixZero))
return affine matrix
void SetDefaultCov()
sets default nonzero cov
virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
specialization of XML write function
BIAS::Matrix2x2< double > A_
"orientation + area(detA) of feature" affine matrix which transforms all pixels of the unit feature (...
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
void SetFromVector(const BIAS::Vector< double > &affineparams)
set from a 6-vector (a11,a12,a21,a22,tx,ty), default cov
void SetFromMatrix(const BIAS::Matrix< double > &affineTransform)
construct from homography-style affine matrix (last row 0,0,1)
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
static int Ellipse(Image< StorageType > &im, double center[2], double a[2], double b[2], const StorageType Value[])
draws an ellipse at center with half axes a and b
void SetT(const BIAS::Vector2< double > &T, const BIAS::Matrix< double > &cov=BIAS::Matrix< double >(2, 2, BIAS::MatrixZero))
return offset
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
specialization of XML read function
int EigenvalueDecomposition(T &value1, Vector2< T > &vector1, T &value2, Vector2< T > &vector2) const
Eigenvalue decomposition.
BIAS::Matrix< double > Cov_
6x6 covariance matrix of the 6 region parameters(a11,a12,a21,a22,tx,ty)
void Draw(BIAS::Image< unsigned char > &targetImage, const double &positionCovScale=1.0, const unsigned int linethickness=1) const
draw a square at the feature's ori position
BIAS::Matrix< double > GetAsInverseMatrix() const
returns matrix which transforms a point in image coordinates into a point in feature coordinates (Glo...
LocalAffineFrame GetHomographyTransformed(const BIAS::HMatrix &H) const
use linear propagation to transform the local affine frame e.g.
void GetSystemMatrix(Matrix< T > &dest) const
compute square system matrix dest = A^T * A
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.