latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiDecimation.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 6.12.2000 00030 * revisions ..: $Id: ltiDecimation.h,v 1.8 2006/02/07 18:44:27 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DECIMATION_H_ 00034 #define _LTI_DECIMATION_H_ 00035 00036 00037 #include "ltiObject.h" 00038 #include "ltiMatrix.h" 00039 #include "ltiVector.h" 00040 #include "ltiFilter.h" 00041 00042 namespace lti { 00043 /** 00044 * Decimation. 00045 * 00046 * To decimate an image or matrix means to take each n-th pixel. It 00047 * is much simpler than lti::downsampling, which also applies a filter 00048 * kernel before the decimation. 00049 * 00050 * You may also be interersted in lti::scaling, which uses interpolation to 00051 * downsample at non-integer scales. 00052 * 00053 * @see lti::upsampling, lti::filledUpsampling, lti::downsampling, 00054 * lti::scaling 00055 */ 00056 class decimation : public filter { 00057 public: 00058 /** 00059 * the parameters for the class decimation 00060 */ 00061 class parameters : public filter::parameters { 00062 public: 00063 /** 00064 * default constructor 00065 */ 00066 parameters(); 00067 00068 /** 00069 * copy constructor 00070 * @param other the parameters object to be copied 00071 */ 00072 parameters(const parameters& other); 00073 00074 /** 00075 * destructor 00076 */ 00077 ~parameters(); 00078 00079 /** 00080 * returns name of this type 00081 */ 00082 const char* getTypeName() const; 00083 00084 /** 00085 * copy the contents of a parameters object 00086 * @param other the parameters object to be copied 00087 * @return a reference to this parameters object 00088 */ 00089 parameters& copy(const parameters& other); 00090 00091 /** 00092 * copy the contents of a parameters object 00093 * @param other the parameters object to be copied 00094 * @return a reference to this parameters object 00095 */ 00096 parameters& operator=(const parameters& other); 00097 00098 /** 00099 * returns a pointer to a clone of the parameters 00100 */ 00101 virtual functor::parameters* clone() const; 00102 00103 /** 00104 * write the parameters in the given ioHandler 00105 * @param handler the ioHandler to be used 00106 * @param complete if true (the default) the enclosing begin/end will 00107 * be also written, otherwise only the data block will be written. 00108 * @return true if write was successful 00109 */ 00110 virtual bool write(ioHandler& handler,const bool complete=true) const; 00111 00112 /** 00113 * write the parameters in the given ioHandler 00114 * @param handler the ioHandler to be used 00115 * @param complete if true (the default) the enclosing begin/end will 00116 * be also written, otherwise only the data block will be written. 00117 * @return true if write was successful 00118 */ 00119 virtual bool read(ioHandler& handler,const bool complete=true); 00120 00121 # ifdef _LTI_MSC_6 00122 /** 00123 * this function is required by MSVC only, as a workaround for a 00124 * very awful bug, which exists since MSVC V.4.0, and still by 00125 * V.6.0 with all bugfixes (so called "service packs") remains 00126 * there... This method is public due to another bug, so please 00127 * NEVER EVER call this method directly: use read() instead! 00128 */ 00129 bool readMS(ioHandler& handler,const bool complete=true); 00130 00131 /** 00132 * this function is required by MSVC only, as a workaround for a 00133 * very awful bug, which exists since MSVC V.4.0, and still by 00134 * V.6.0 with all bugfixes (so called "service packs") remains 00135 * there... This method is public due to another bug, so please 00136 * NEVER EVER call this method directly: use write() instead! 00137 */ 00138 bool writeMS(ioHandler& handler,const bool complete=true) const; 00139 # endif 00140 00141 // ------------------------------------------------ 00142 // the parameters 00143 // ------------------------------------------------ 00144 00145 /** 00146 * the decimation factor 00147 * Only the pixels with coordinates x=n*factor.x and y=m*factor.y, with 00148 * n and m integers will be taken. For vector decimation, only factor.x 00149 * will be considered. 00150 * the default value is (2,2) 00151 */ 00152 point factor; 00153 }; 00154 00155 /** 00156 * default constructor 00157 */ 00158 decimation(); 00159 00160 /** 00161 * constructor with a default parameters with the decimation factor 00162 * given by the point factor. (see lti::decimation::parameters::factor) 00163 */ 00164 decimation(const point& factor); 00165 00166 /** 00167 * copy constructor 00168 * @param other the object to be copied 00169 */ 00170 decimation(const decimation& other); 00171 00172 /** 00173 * destructor 00174 */ 00175 virtual ~decimation(); 00176 00177 /** 00178 * returns the name of this type ("decimation") 00179 */ 00180 virtual const char* getTypeName() const; 00181 00182 /** 00183 * operates on the given %parameter. 00184 * @param srcdest matrix<T> with the source data. The result 00185 * will be left here too. 00186 * @return true if successful, false otherwise. 00187 */ 00188 template<class T> 00189 bool apply(matrix<T>& srcdest) const { 00190 // implementation must be here due to MS-VC++ bug 00191 matrix<T> tmp; 00192 if (apply(srcdest,tmp)) { 00193 tmp.detach(srcdest); 00194 return true; 00195 } 00196 return false; 00197 }; 00198 00199 /** 00200 * operates on the given %parameter. 00201 * @param srcdest vector<T> with the source data. The result 00202 * will be left here too. 00203 * @return true if successful, false otherwise. 00204 */ 00205 template<class T> 00206 bool apply(vector<T>& srcdest) const { 00207 // implementation must be here due to MS-VC++ bug 00208 vector<T> tmp; 00209 if (apply(srcdest,tmp)) { 00210 tmp.detach(srcdest); 00211 return true; 00212 } 00213 return false; 00214 }; 00215 00216 /** 00217 * operates on a copy of the given %parameters. 00218 * @param src matrix<T> with the source data. 00219 * @param dest matrix<T> where the result will be left. 00220 * @return true if successful, false otherwise. 00221 */ 00222 template<class T> 00223 bool apply(const matrix<T>& src,matrix<T>& dest) const { 00224 // implementation must be here due to MS-VC++ bug 00225 point newSize; 00226 const parameters& param = getParameters(); 00227 00228 newSize.x = (src.columns()+(param.factor.x-1))/param.factor.x; 00229 newSize.y = (src.rows()+(param.factor.y-1))/param.factor.y; 00230 00231 dest.resize(newSize,T(),false,false); 00232 int y,x,yy; 00233 typename vector<T>::iterator it,eit; 00234 00235 for (y=0,yy=0;yy<dest.rows();y+=param.factor.y,++yy) { 00236 vector<T>& vct = dest.getRow(yy); 00237 for (x=0,it=vct.begin(),eit=vct.end();it!=eit;x+=param.factor.x,++it) { 00238 (*it)=src.at(y,x); 00239 } 00240 } 00241 00242 return true; 00243 }; 00244 00245 /** 00246 * operates on a copy of the given %parameters. 00247 * @param src vector<T> with the source data. 00248 * @param dest vector<T> where the result will be left. 00249 * @return true if successful, false otherwise. 00250 */ 00251 template<class T> 00252 bool apply(const vector<T>& src,vector<T>& dest) const { 00253 // implementation must be here due to MS-VC++ bug 00254 00255 int newSize; 00256 const parameters& param = getParameters(); 00257 00258 newSize = (src.columns()+(param.factor.x-1))/param.factor.x; 00259 00260 dest.resize(newSize,T(),false,false); 00261 int x; 00262 typename vector<T>::iterator it,eit; 00263 00264 for (x=0,it=dest.begin(),eit=dest.end();it!=eit;x+=param.factor.x,++it) { 00265 (*it)=src.at(x); 00266 } 00267 00268 return true; 00269 }; 00270 00271 /** 00272 * copy data of "other" functor. 00273 * @param other the functor to be copied 00274 * @return a reference to this functor object 00275 */ 00276 decimation& copy(const decimation& other); 00277 00278 /** 00279 * returns a pointer to a clone of this functor. 00280 */ 00281 virtual functor* clone() const; 00282 00283 /** 00284 * returns used parameters 00285 */ 00286 const parameters& getParameters() const; 00287 }; 00288 } 00289 00290 // due to MS-VC++ bug this file lost its value 00291 //#include "ltiDecimation_template.h" 00292 00293 #endif