LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiScaling.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiScaling.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 21.11.2003
00030  * revisions ..: $Id: ltiScaling.h,v 1.8 2006/02/08 11:48:04 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_SCALING_H_
00034 #define _LTI_SCALING_H_
00035 
00036 #include "ltiModifier.h"
00037 #include "ltiInterpolatorType.h"
00038 
00039 namespace lti {
00040 
00041   // this is a private class defined in the cpp file for internal use only
00042   class scalingWorker;
00043 
00044   /**
00045    * Scaling implements a functor to rescale an image using a real valued
00046    * scaling factor.
00047    *
00048    * This functor represents a faster alternative to lti::geometricTransform,
00049    * used if you only need to scale the image, without any other kind of 
00050    * geometric mapping.
00051    * 
00052    * It is usually employed to upsample an image, using some interpolation
00053    * policy indicated in the parameters.  At this point only bilinear
00054    * interpolation is supported, but this may change as soon as the new
00055    * family of interpolators for the LTI-Lib are available.
00056    *
00057    * You can give also factors smaller than one to downsample an image, but
00058    * this will just take the interpolated corresponding pixel of the original
00059    * image, without consideration of its neighborhood.  For a more
00060    * theoretically founded downsampling functor, you can use
00061    * lti::downsampling, which allows you to make a low-pass filtering, to
00062    * avoid artifacts resulting from a violation of the Nyquist sampling
00063    * theorem.  Nevertheless, if you just one to downsample for some
00064    * visualization, this functor might be enough (lti::decimation can be even
00065    * faster if the downsampling factor is integer).
00066    * 
00067    *
00068    * For more complex operations you can still use the lti::geometricTransform 
00069    * functor.
00070    *
00071    * @see lti::geometricTransform, lti::rotation, lti::flipImage
00072    *
00073    * @see lti::downsampling, lti::upsampling, lti::filledUpsampling, 
00074    *      lti::decimation
00075    *
00076    * @ingroup gGeometry
00077    */
00078   class scaling : public modifier {
00079   public:
00080     /**
00081      * The parameters for the class scaling
00082      */
00083     class parameters : public modifier::parameters {
00084     public:
00085       /**
00086        * Default constructor
00087        */
00088       parameters();
00089 
00090       /**
00091        * Copy constructor
00092        * @param other the parameters object to be copied
00093        */
00094       parameters(const parameters& other);
00095 
00096       /**
00097        * Destructor
00098        */
00099       ~parameters();
00100 
00101       /**
00102        * Returns name of this type
00103        */
00104       const char* getTypeName() const;
00105 
00106       /**
00107        * Copy the contents of a parameters object
00108        * @param other the parameters object to be copied
00109        * @return a reference to this parameters object
00110        */
00111       parameters& copy(const parameters& other);
00112 
00113       /**
00114        * Copy the contents of a parameters object
00115        * @param other the parameters object to be copied
00116        * @return a reference to this parameters object
00117        */
00118       parameters& operator=(const parameters& other);
00119 
00120 
00121       /**
00122        * Returns a pointer to a clone of the parameters
00123        */
00124       virtual functor::parameters* clone() const;
00125 
00126       /**
00127        * Write the parameters in the given ioHandler
00128        * @param handler the ioHandler to be used
00129        * @param complete if true (the default) the enclosing begin/end will
00130        *        be also written, otherwise only the data block will be written.
00131        * @return true if write was successful
00132        */
00133       virtual bool write(ioHandler& handler,const bool complete=true) const;
00134 
00135       /**
00136        * Read the parameters from the given ioHandler
00137        * @param handler the ioHandler to be used
00138        * @param complete if true (the default) the enclosing begin/end will
00139        *        be also written, otherwise only the data block will be written.
00140        * @return true if write was successful
00141        */
00142       virtual bool read(ioHandler& handler,const bool complete=true);
00143 
00144 #     ifdef _LTI_MSC_6
00145       /**
00146        * This function is required by MSVC only, as a workaround for a
00147        * very awful bug, which exists since MSVC V.4.0, and still by
00148        * V.6.0 with all bugfixes (so called "service packs") remains
00149        * there...  This method is also public due to another bug, so please
00150        * NEVER EVER call this method directly: use read() instead
00151        */
00152       bool readMS(ioHandler& handler,const bool complete=true);
00153 
00154       /**
00155        * This function is required by MSVC only, as a workaround for a
00156        * very awful bug, which exists since MSVC V.4.0, and still by
00157        * V.6.0 with all bugfixes (so called "service packs") remains
00158        * there...  This method is also public due to another bug, so please
00159        * NEVER EVER call this method directly: use write() instead
00160        */
00161       bool writeMS(ioHandler& handler,const bool complete=true) const;
00162 #     endif
00163 
00164       // ------------------------------------------------
00165       // the parameters
00166       // ------------------------------------------------
00167 
00168       /**
00169        * Scaling factor.
00170        *
00171        * Each axis of the image can be scaled by a different factor.  The
00172        * \a x component of this point will be the horizontal scaling factor and
00173        * the \a y component the vertical scaling factor.
00174        *
00175        * Only positive values are allowed.  You can flip you image using
00176        * lti::flipImage if you need to first. 
00177        *
00178        * With \a scale between 0 and 1 this functor does a down-sampling and
00179        * above 1.0 up-sampling.
00180        *
00181        * Default value: tpoint<float>(sqrt(2),sqrt(2))
00182        */
00183       tpoint<float> scale;
00184 
00185       /**
00186        * Interpolator type to be used.
00187        *
00188        * Default value: BilinearInterpolator
00189        */
00190       eInterpolatorType interpolatorType;
00191     };
00192 
00193     /**
00194      * Default constructor
00195      */
00196     scaling();
00197 
00198     /**
00199      * Construct a functor using the given parameters
00200      */
00201     scaling(const parameters& par);
00202 
00203     /**
00204      * Copy constructor
00205      * @param other the object to be copied
00206      */
00207     scaling(const scaling& other);
00208 
00209     /**
00210      * Destructor
00211      */
00212     virtual ~scaling();
00213 
00214     /**
00215      * Returns the name of this type ("scaling")
00216      */
00217     virtual const char* getTypeName() const;
00218     
00219     /**
00220      * @name Standard apply methods.
00221      *
00222      * The scaling factor and interpolation types are taken from the parameters
00223      */
00224     //@{
00225     /**
00226      * Operates on the given %parameter.
00227      * @param srcdest image with the source data.  The result
00228      *                 will be left here too.
00229      * @return true if apply successful or false otherwise.
00230      */
00231     bool apply(image& srcdest) const;
00232 
00233     /**
00234      * Operates on a copy of the given %parameters.
00235      * @param src image with the source data.
00236      * @param dest image where the result will be left.
00237      * @return true if apply successful or false otherwise.
00238      */
00239     bool apply(const image& src,image& dest) const;
00240 
00241 
00242     /**
00243      * Operates on the given %parameter.
00244      * @param srcdest matrix<ubyte> with the source data.  The result
00245      *                 will be left here too.
00246      * @return true if apply successful or false otherwise.
00247      */
00248     bool apply(matrix<ubyte>& srcdest) const;
00249 
00250     /**
00251      * Operates on a copy of the given %parameters.
00252      * @param src matrix<ubyte> with the source data.
00253      * @param dest matrix<ubyte> where the result will be left.
00254      * @return true if apply successful or false otherwise.
00255      */
00256     bool apply(const matrix<ubyte>& src,matrix<ubyte>& dest) const;
00257 
00258     /**
00259      * Operates on the given %parameter.
00260      * @param srcdest matrix<float> with the source data.  The result
00261      *                 will be left here too.
00262      * @return true if apply successful or false otherwise.
00263      */
00264     bool apply(matrix<float>& srcdest) const;
00265 
00266     /**
00267      * Operates on a copy of the given %parameters.
00268      * @param src matrix<float> with the source data.
00269      * @param dest matrix<float> where the result will be left.
00270      * @return true if apply successful or false otherwise.
00271      */
00272     bool apply(const matrix<float>& src,matrix<float>& dest) const;
00273 
00274     /**
00275      * Operates on the given %parameter.
00276      * @param srcdest matrix<int> with the source data.  The result
00277      *                 will be left here too.
00278      * @return true if apply successful or false otherwise.
00279      */
00280     bool apply(matrix<int>& srcdest) const;
00281 
00282     /**
00283      * Operates on a copy of the given %parameters.
00284      * @param src matrix<int> with the source data.
00285      * @param dest matrix<int> where the result will be left.
00286      * @return true if apply successful or false otherwise.
00287      */
00288     bool apply(const matrix<int>& src,matrix<int>& dest) const;
00289     //@}
00290 
00291     /**
00292      * @name Symmetric scaling apply methods.
00293      *
00294      * The scaling factor for both vertical and horizontal axes is given
00295      * directly.
00296      */
00297     //@{
00298     /**
00299      * Operates on the given %parameter.
00300      * @param scale scaling factor used for both, the horizontal and vertical
00301      *             axes.  The scaling factor in the parameters will be ignored.
00302      * @param srcdest image with the source data.  The result
00303      *                 will be left here too.
00304      * @return true if apply successful or false otherwise.
00305      */
00306     bool apply(const float scale,image& srcdest) const;
00307 
00308     /**
00309      * Operates on a copy of the given %parameters.
00310      * @param scale scaling factor used for both, the horizontal and vertical 
00311      *            axes.  The scaling factor in the parameters will be ignored.
00312      * @param src image with the source data.
00313      * @param dest image where the result will be left.
00314      * @return true if apply successful or false otherwise.
00315      */
00316     bool apply(const float scale,const image& src,image& dest) const;
00317 
00318 
00319     /**
00320      * Operates on the given %parameter.
00321      * @param scale scaling factor used for both, the horizontal and vertical
00322      *             axes.  The scaling factor in the parameters will be ignored.
00323      * @param srcdest matrix<ubyte> with the source data.  The result
00324      *                 will be left here too.
00325      * @return true if apply successful or false otherwise.
00326      */
00327     bool apply(const float scale,matrix<ubyte>& srcdest) const;
00328 
00329     /**
00330      * Operates on a copy of the given %parameters.
00331      * @param scale scaling factor used for both, the horizontal and vertical
00332      *             axes.  The scaling factor in the parameters will be ignored.
00333      * @param src matrix<ubyte> with the source data.
00334      * @param dest matrix<ubyte> where the result will be left.
00335      * @return true if apply successful or false otherwise.
00336      */
00337     bool apply(const float scale,
00338                const matrix<ubyte>& src,
00339                matrix<ubyte>& dest) const;
00340 
00341     /**
00342      * Operates on the given %parameter.
00343      * @param scale scaling factor used for both, the horizontal and vertical 
00344      *             axes.  The scaling factor in the parameters will be ignored.
00345      * @param srcdest matrix<float> with the source data.  The result
00346      *                 will be left here too.
00347      * @return true if apply successful or false otherwise.
00348      */
00349     bool apply(const float scale,
00350                matrix<float>& srcdest) const;
00351 
00352     /**
00353      * Operates on a copy of the given %parameters.
00354      * @param scale scaling factor used for both, the horizontal and vertical
00355      *             axes.  The scaling factor in the parameters will be ignored.
00356      * @param src matrix<float> with the source data.
00357      * @param dest matrix<float> where the result will be left.
00358      * @return true if apply successful or false otherwise.
00359      */
00360     bool apply(const float scale,
00361                const matrix<float>& src,matrix<float>& dest) const;
00362 
00363    /**
00364      * Operates on the given %parameter.
00365      * @param scale scaling factor used for both, the horizontal and vertical 
00366      *             axes.  The scaling factor in the parameters will be ignored.
00367      * @param srcdest matrix<int> with the source data.  The result
00368      *                 will be left here too.
00369      * @return true if apply successful or false otherwise.
00370      */
00371     bool apply(const float scale,
00372                matrix<int>& srcdest) const;
00373 
00374     /**
00375      * Operates on a copy of the given %parameters.
00376      * @param scale scaling factor used for both, the horizontal and vertical
00377      *             axes.  The scaling factor in the parameters will be ignored.
00378      * @param src matrix<int> with the source data.
00379      * @param dest matrix<int> where the result will be left.
00380      * @return true if apply successful or false otherwise.
00381      */
00382     bool apply(const float scale,
00383                const matrix<int>& src,matrix<int>& dest) const;
00384 
00385     /**
00386      * @name Asymmetric scaling apply methods.
00387      *
00388      * The scaling factor for horizontal and vertical axes are given through
00389      * the x and y components of the point respectivelly.
00390      */
00391     //@{
00392     /**
00393      * Operates on the given %parameter.
00394      * @param scale scaling factor used instead of the value given in the
00395      *              parameters object.
00396      * @param srcdest image with the source data.  The result
00397      *                 will be left here too.
00398      * @return true if apply successful or false otherwise.
00399      */
00400     bool apply(const tpoint<float>& scale,image& srcdest) const;
00401 
00402     /**
00403      * Operates on a copy of the given %parameters.
00404      * @param scale scaling factor used instead of the value given in the
00405      *              parameters object.
00406      * @param src image with the source data.
00407      * @param dest image where the result will be left.
00408      * @return true if apply successful or false otherwise.
00409      */
00410     bool apply(const tpoint<float>& scale,const image& src,image& dest) const;
00411 
00412 
00413     /**
00414      * Operates on the given %parameter.
00415      * @param scale scaling factor used instead of the value given in the
00416      *              parameters object.
00417      * @param srcdest matrix<ubyte> with the source data.  The result
00418      *                 will be left here too.
00419      * @return true if apply successful or false otherwise.
00420      */
00421     bool apply(const tpoint<float>& scale,matrix<ubyte>& srcdest) const;
00422 
00423     /**
00424      * Operates on a copy of the given %parameters.
00425      * @param scale scaling factor used instead of the value given in the
00426      *              parameters object.
00427      * @param src matrix<ubyte> with the source data.
00428      * @param dest matrix<ubyte> where the result will be left.
00429      * @return true if apply successful or false otherwise.
00430      */
00431     bool apply(const tpoint<float>& scale,
00432                const matrix<ubyte>& src,
00433                matrix<ubyte>& dest) const;
00434 
00435     /**
00436      * Operates on the given %parameter.
00437      * @param scale scaling factor used instead of the value given in the
00438      *              parameters object.
00439      * @param srcdest matrix<float> with the source data.  The result
00440      *                 will be left here too.
00441      * @return true if apply successful or false otherwise.
00442      */
00443     bool apply(const tpoint<float>& scale,
00444                matrix<float>& srcdest) const;
00445 
00446     /**
00447      * Operates on a copy of the given %parameters.
00448      * @param scale scaling factor used instead of the value given in the 
00449      *              parameters object.
00450      * @param src matrix<float> with the source data.
00451      * @param dest matrix<float> where the result will be left.
00452      * @return true if apply successful or false otherwise.
00453      */
00454     bool apply(const tpoint<float>& scale,
00455                const matrix<float>& src,matrix<float>& dest) const;
00456 
00457     /**
00458      * Operates on the given %parameter.
00459      * @param scale scaling factor used instead of the value given in the
00460      *              parameters object.
00461      * @param srcdest matrix<int> with the source data.  The result
00462      *                 will be left here too.
00463      * @return true if apply successful or false otherwise.
00464      */
00465     bool apply(const tpoint<float>& scale,
00466                matrix<int>& srcdest) const;
00467 
00468     /**
00469      * Operates on a copy of the given %parameters.
00470      * @param scale scaling factor used instead of the value given in the 
00471      *              parameters object.
00472      * @param src matrix<int> with the source data.
00473      * @param dest matrix<int> where the result will be left.
00474      * @return true if apply successful or false otherwise.
00475      */
00476     bool apply(const tpoint<float>& scale,
00477                const matrix<int>& src,matrix<int>& dest) const;
00478 
00479     //@}
00480 
00481     /**
00482      * Copy data of "other" functor.
00483      * @param other the functor to be copied
00484      * @return a reference to this functor object
00485      */
00486     scaling& copy(const scaling& other);
00487 
00488     /**
00489      * Alias for copy member
00490      * @param other the functor to be copied
00491      * @return a reference to this functor object
00492      */
00493     scaling& operator=(const scaling& other);
00494 
00495     /**
00496      * Returns a pointer to a clone of this functor.
00497      */
00498     virtual functor* clone() const;
00499 
00500     /**
00501      * Returns used parameters
00502      */
00503     const scaling::parameters& getParameters() const;
00504 
00505     /**
00506      * returns used parameters
00507      */
00508     virtual bool updateParameters();
00509 
00510   protected:
00511     /**
00512      * Class containing the real algorithms.
00513      * This is set in setParameters();
00514      */
00515     scalingWorker* worker;
00516   };
00517 }
00518 
00519 #endif

Generated on Sat Apr 10 15:26:07 2010 for LTI-Lib by Doxygen 1.6.1