latest version v1.9 - last update 10 Apr 2010 |
00001 00002 /* 00003 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 00004 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00005 * 00006 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00007 * 00008 * The LTI-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00010 * as published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * The LTI-Lib is distributed in the hope that it will be 00014 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00015 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with the LTI-Lib; see the file LICENSE. If 00020 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00021 * Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 00024 00025 /*---------------------------------------------------------------- 00026 * project ....: LTI Digital Image/Signal Processing Library 00027 * file .......: ltiBicubicInterpolator.h 00028 * authors ....: Jens Rietzschel 00029 * organization: LTI, RWTH Aachen 00030 * creation ...: 4.10.2001 00031 * revisions ..: $Id: ltiBicubicInterpolator.h,v 1.6 2006/02/07 18:29:44 ltilib Exp $ 00032 */ 00033 00034 #ifndef _LTI_BICUBIC_INTERPOLATOR_H_ 00035 #define _LTI_BICUBIC_INTERPOLATOR_H_ 00036 00037 #include "ltiScalarValuedInterpolation.h" 00038 00039 00040 namespace lti { 00041 /** 00042 * This functor use bicubic interpolation to approximate values 00043 * between the pixels or elements of vectors and matrices. 00044 * 00045 * The type T of the template is the type of the elements of the vector 00046 * or matrix used. 00047 */ 00048 template<class T> 00049 class bicubicInterpolator : public scalarValuedInterpolation<T> { 00050 public: 00051 00052 /** 00053 * default constructor 00054 */ 00055 bicubicInterpolator(); 00056 00057 /** 00058 * copy constructor 00059 * @param other the object to be copied 00060 */ 00061 bicubicInterpolator(const bicubicInterpolator& other); 00062 00063 /** 00064 * destructor 00065 */ 00066 virtual ~bicubicInterpolator(); 00067 00068 /** 00069 * returns the name of this type ("bicubicInterpolator") 00070 */ 00071 virtual const char* getTypeName() const; 00072 00073 /** 00074 * Returns the interpolated value of the vector at the real valued 00075 * position x. 00076 * @param src vector<T> with the source data. 00077 * @param x the real valued position to be interpolated. 00078 * @return the interpolated value of the vector. 00079 */ 00080 virtual T apply(const vector<T>& src,const float& x) const; 00081 00082 /** 00083 * Returns the interpolated value of the vector specified with 00084 * use() at the real valued position x. 00085 * @param x the real valued position to be interpolated. 00086 * @return the interpolated value of the vector. */ 00087 virtual T apply(const float& x) const; 00088 00089 /** 00090 * Returns the interpolated value of the matrix at the real valued 00091 * position (row,col). 00092 * 00093 * @param srcdest matrix<T> with the source and destination data. 00094 * @param row which row 00095 * @param col which column 00096 * @return the interpolated value of the matrix. 00097 */ 00098 virtual T apply(const matrix<T>& srcdest, 00099 const float& row, 00100 const float& col) const; 00101 00102 /** 00103 * Returns the interpolated value of the matrix at the real valued 00104 * position p. 00105 * 00106 * @param src matrix<T> with the source data. 00107 * @param p the real valued position to be interpolated. 00108 * @return the interpolated value of the matrix. 00109 */ 00110 inline T apply(const matrix<T>& src,const tpoint<float>& p) const { 00111 return apply(src,p.y,p.x); 00112 }; 00113 00114 00115 /** 00116 * Returns the interpolated value of the matrix specified with 00117 * use() at the real valued position p. 00118 * @param p the real valued position to be interpolated. 00119 * @return the interpolated value of the matrix. 00120 */ 00121 inline T apply(const tpoint<float>& p) const { 00122 return apply(p.y,p.x); 00123 }; 00124 00125 /** 00126 * Returns the interpolated value of the matrix specified with 00127 * use() at the real valued position (row,col). 00128 * 00129 * @param row which row 00130 * @param col which column 00131 * @return the interpolated value of the matrix. */ 00132 virtual T apply(const float& row, const float& col) const; 00133 00134 /** 00135 * Returns the interpolated value of the gradient of the matrix src 00136 * at the real valued position (row,col). 00137 * dest.x row-direction dest.y column-direction 00138 * @param src matrix with the source data 00139 * @param row which row 00140 * @param col which column 00141 * @param dest gradient 00142 */ 00143 bool getGradient(const matrix<T>& src,const float& row, const float& col, 00144 tpoint<T>& dest) const; 00145 00146 /** 00147 * copy data of "other" functor. 00148 * @param other the functor to be copied 00149 * @return a reference to this functor object 00150 */ 00151 bicubicInterpolator& copy(const bicubicInterpolator& other); 00152 00153 /** 00154 * alias for copy member 00155 * @param other the functor to be copied 00156 * @return a reference to this functor object 00157 */ 00158 bicubicInterpolator<T>& operator=(const bicubicInterpolator<T>& other); 00159 00160 /** 00161 * returns a pointer to a clone of this functor. 00162 */ 00163 virtual functor* clone() const; 00164 00165 private: 00166 00167 /** 00168 * The grid square containing the desired point for interpolation 00169 * is considered here. The four points are numbered 00170 * counterclockwise starting at the low left corner.Within the 00171 * loop the function value, the gradients, and the cross 00172 * derivative are determined and stored in 00173 * y[4],y1[4],y2[4],y12[4]. 00174 * 00175 * This is all the information needed from the given matrix to 00176 * compute the interpolation value(done in bicubicInterpolation ). 00177 */ 00178 void centeredDifferencing(float row,float col,float& t,float& u, 00179 float y[4],float y1[4], float y2[4], 00180 float y12[4],const matrix<T>& src) const; 00181 00182 00183 /** 00184 * like centeredDifferencing but used at the border of the matrix 00185 */ 00186 void centeredDifferencingBorder(float row,float col,float& t,float& u, 00187 float y[4],float y1[4], float y2[4], 00188 float y12[4],const matrix<T>& src) const; 00189 00190 00191 /** 00192 * This method computes the interpolation value(only for 00193 * matrixes). The value is returned in result, whereas gradient1 and 00194 * gradient2 give the interpolated gradients 00195 */ 00196 void bicubicInterpolation(float y[4],float y1[4],float y2[4],float y12[4], 00197 float row,float col,float t,float u, 00198 T& result, 00199 float &gradient1, 00200 float &gradient2) const; 00201 00202 00203 /** 00204 * This method computes the interpolation value for vectors using 00205 * the newton polynom of second degree.The values next to the 00206 * desired point and one to the left are used for the polynom 00207 */ 00208 T newtonInterpolation(const int x[3],const T y[3], 00209 const float & toinpol) const; 00210 00211 /** 00212 * get bilinear interpolated value 00213 */ 00214 void bilinearInterpolation(const matrix<T>& src, 00215 float row,float col,T& result)const; 00216 00217 /** 00218 * extraPolation is used for interpolation beyond the borders. The 00219 * boundaryType is decisive for the result 00220 */ 00221 void extraPolation(float row,float col,const matrix<T>& src,T& result, 00222 float &gradient1,float &gradient2) const; 00223 }; 00224 00225 } 00226 00227 #endif