Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AffineMapping.hh
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 
27 #ifndef __AffineMapping_hh__
28 #define __AffineMapping_hh__
29 
30 #include <Image/BackwardMapping.hh>
31 
32 namespace BIAS
33 {
34 
35  /** @class AffineMapping
36  @ingroup g_filter
37  @brief Maps image src to image sink with affine transformation
38 
39  MapDirect takes care of correct filtering and texture preservation for
40  grey images (efficient anisotropic filtering)
41  @author koeser 01/2007
42  */
43  template<class InputStorageType, class OutputStorageType>
44  class BIASImage_EXPORT AffineMapping : public BackwardMapping<
45  InputStorageType, OutputStorageType>
46  {
47  public:
48 
49  virtual
50  ~AffineMapping();
51 
52  AffineMapping();
53 
54  /** required because assignment is
55  @author Jan Woetzel */
57  {
58  (*this) = src;
59  }
60 
61  /** required because of const members
62  @author Jan Woetzel */
64  operator=(const AffineMapping & src)
65  {
66  BIASERR ( "dont copy me - not implemented." );
67  BIASABORT;
68  return *this;
69  }
70 
71  /** @brief set A (source = A * sink) before calling Map()*/
72  inline void
73  SetAffineTransformation(const double&a11, const double&a12,
74  const double&a21, const double&a22, const double& dx,
75  const double& dy)
76  {
77  a11_ = a11;
78  a12_ = a12;
79  a21_ = a21;
80  a22_ = a22;
81  dx_ = dx;
82  dy_ = dy;
83  }
84  ;
85 
86  /** @brief direct, fast implementation of affine backward mapping with
87  anisotropic filtering, one channel grey only */
88  int
89  MapDirect(const Image<InputStorageType>& src,
91 
92  /** @brief after first MapDirect, call this function to reuse last pyramid*/
93  int
94  MapDirectAgain(Image<OutputStorageType>& sink);
95 
96  /** @brief direct, fast implementation of affine backward mapping with
97  bilinear filtering, one channel grey only */
98  int
99  BilinearGrey(const Image<InputStorageType>& src,
101 
102  /** @brief direct, fast implementation of affine backward mapping with
103  bilinear filtering, one channel grey only */
104  int
105  TrilinearGrey(const Image<InputStorageType>& src,
106  Image<OutputStorageType>& sink, double scale = -1.0);
107  /** @brief after first TrilinearGrey, call this function to reuse
108  last pyramid*/
109  int
110  TrilinearGreyAgain(Image<OutputStorageType>& sink, double scale = -1.0);
111 
112  /** @brief computes local stretching factors, large >> 1 means that the
113  sink image can contain significant aliasing when using bilinear
114  @param cosphi cosine of angle between x-axis and largest scale
115  @param costheta upper bound on rotation after scaling, cf HMatrix
116  */
117  int
118  ComputeScales(double& large, double& smallN, double& cosphi,
119  double& costheta) const;
120 
121  /** calculates the bounding box in sink image,
122  where to do the backward mapping.
123  The resulting coordinates must be valid in sink, and the resulting
124  br position should be outside the region.
125  @author grest, Nov. 2005
126  */
127  virtual int
128  GetBoundingBox(unsigned int srcwidth, unsigned int srcheight,
129  unsigned int sinkwidth, unsigned int sinkheight, int &tlx, int &tly,
130  int &brx, int &bry);
131 
132  protected:
133  /** @brief reimplementation for homography, takes sink and computes
134  coords in source */
135  virtual int
136  GetSourceCoordinates_(const HomgPoint2D& sink, HomgPoint2D& source) const;
137 
138  /** @brief analytic jacobian */
139  virtual int
140  GetJacobian_(const HomgPoint2D& sink, Matrix2x2<double>& Jacobian) const;
141 
142  /// the homography for backward mapping: run over sink and compute
143  /// source = A * sink + d
144  double a11_;
145  double a12_;
146  double a21_;
147  double a22_;
148  double dx_;
149  double dy_;
150 
153 
154  };
155 
156 } // namespace
157 
158 #endif
159 
160 #include <Base/Common/BIASpragmaEnd.hh>
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
double a11_
the homography for backward mapping: run over sink and compute source = A * sink + d ...
Abstract base class to map an image (texture) src to an image sink with an arbitrary continuous funct...
AffineMapping(const AffineMapping &src)
required because assignment is
Maps image src to image sink with affine transformation.
void SetAffineTransformation(const double &a11, const double &a12, const double &a21, const double &a22, const double &dx, const double &dy)
set A (source = A * sink) before calling Map()
AffineMapping< InputStorageType, OutputStorageType > & operator=(const AffineMapping &src)
required because of const members