Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LogPolarMapping.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 "Image/LogPolarMapping.hh"
26 #include <Base/Geometry/HomgPoint2D.hh>
27 
28 using namespace BIAS;
29 using namespace std;
30 
31 
32 template <class InputStorageType, class OutputStorageType>
35 {}
36 
37 template <class InputStorageType, class OutputStorageType>
40 {}
41 
42 template <class InputStorageType, class OutputStorageType>
45 {
46  (*this) = src;
47 }
48 
49 template <class InputStorageType, class OutputStorageType>
53 {
54  XCenter_ = src.XCenter_;
55  YCenter_ = src.YCenter_;
56  return *this;
57 }
58 
59 template <class InputStorageType, class OutputStorageType>
61 SetImageCenter(const int & x, const int & y)
62 {
63  double a,r;
64 
65  XCenter_ = x;
66  YCenter_ = y;
67  _XYMap = (HomgPoint2D*) calloc(2*x*2*y,sizeof(HomgPoint2D));
68  for(int i=0;i<2*x;i++){
69  for(int j=0;j<2*y;j++){
70  //map image height to 0 - PI (180 Deg)
71  a = 0.5*M_PI*(double)j/(double)YCenter_;
72  //map image width to minimum of center coords
73  r = (double) pow((double)XCenter_,(double)i/(double)(2*XCenter_));
74  //calculate source pixle position
75  _XYMap[i+j*2*x][0] = sin(a) * r;
76  _XYMap[i+j*2*x][1] = YCenter_ + cos(a) * r;
77  }
78  }
79 
80 }
81 
82 template <class InputStorageType, class OutputStorageType>
85  HomgPoint2D & source) const {
86  /*
87  double a,r;
88  //map image height to 0 - PI (180 Deg)
89  a = 0.5*M_PI*(double)sink[1]/(double)YCenter_;
90  //map image width to minimum of center coords
91  r = (double) pow((double)XCenter_,(double)sink[0]/(double)(2*XCenter_));
92  //r=exp(log((double)XCenter_)*(double)sink[0]/(2.0*(double)XCenter_));
93  //calculate source pixle position
94  source[0] = sin(a) * r;
95  source[1] = YCenter_ + cos(a) * r;
96  */
97  source[0] = _XYMap[(int)sink[0]+2*XCenter_*(int)sink[1]][0];
98  source[1] = _XYMap[(int)sink[0]+2*XCenter_*(int)sink[1]][1];
99  return 0;
100 }
101 
102 namespace BIAS{
103 // TODO FIXME win32 template instantiation problem (JW)
105 template class LogPolarMapping<float, float>;
107 
108 #if defined(BUILD_IMAGE_CHAR)
109 // TODO FIXME win32 template instantiation problem (JW)
111 template class LogPolarMapping<char, char>;
112 #endif
113 
114 #if defined(BUILD_IMAGE_USHORT)
116 #endif
117 
118 #if defined(BUILD_IMAGE_SHORT)
119 template class LogPolarMapping<short, short>;
120 #endif
121 
122 #if defined(BUILD_IMAGE_SHORT)&&defined(BUILD_IMAGE_USHORT)
124 #endif
125 
126 #if defined(BUILD_IMAGE_INT)
127 template class LogPolarMapping<int,int>;
128 #endif
129 
130 #if defined(BUILD_IMAGE_USHORT)
132 #endif
133 
134 #if defined(BUILD_IMAGE_USHORT) && defined(BUILD_IMAGE_INT)
136 #endif
137 
138 #if defined(BUILD_IMAGE_DOUBLE)
139 template class LogPolarMapping<double,double>;
140 #endif
141 }
Maps cartesian source coordinates to log-polar sink coordinates.
virtual int GetSourceCoordinates_(const HomgPoint2D &sink, HomgPoint2D &source) const
reimplementation for Pixel transformation, takes sink and computes coords in source ...
LogPolarMapping< InputStorageType, OutputStorageType > & operator=(const LogPolarMapping &src)
required because of const members
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void SetImageCenter(const int &x, const int &y)
set your image center before calling Map().