Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GenConvolImage.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------*
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2004  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the license. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 #ifndef __GENCONVOLIMAGE_H_INCLUDED__
00029 #define __GENCONVOLIMAGE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     GenConvolImage.H
00034  * @brief    Header file of class qgar::GenConvolImage.
00035  *
00036  * @author   <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a>
00037  * @date     January 5, 2004  11:05
00038  * @since    Qgar 2.1.1
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: GenConvolImage.H,v 1.19 2005/10/14 17:05:46 masini Exp $ */
00044 
00045 
00046 
00047 // QGAR
00048 #include <qgarlib/GenImage.H>
00049 #include <qgarlib/GenMask1d.H>
00050 #include <qgarlib/GenMask2d.H>
00051 
00052 
00053 
00054 namespace qgar
00055 {
00056 
00057 
00058 /**
00059  * @ingroup IMGPROC_CONVOL
00060  *
00061  * @class GenConvolImage GenConvolImage.H "qgarlib/GenConvolImage.H"
00062  *
00063  * @brief Convolution of an image by a 1D or 2D mask.
00064  *
00065  * The code implementing this class is an adaptation of code written by
00066  * Carsten Steger at TU Muenchen, Germany.
00067  * Here is the corresponding copyright notice:
00068 @verbatim
00069  +----------------------------------------------------------------------+
00070  | Copyright (C) 1996 Carsten Steger                                    |
00071  |                                                                      |
00072  | This program is free software; you can redistribute it and/or modify |
00073  | it under the terms of the GNU General Public License as published by |
00074  | the Free Software Foundation; either version 2, or (at your option)  |
00075  | any later version.                                                   |
00076  |                                                                      |
00077  | This program is distributed in the hope that it will be useful, but  |
00078  | WITHOUT ANY WARRANTY; without even the implied warranty of           |
00079  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
00080  | General Public License for more details.                             |
00081  |                                                                      |
00082  | You should have received a copy of the GNU General Public License    |
00083  | along with this program; if not, write to the Free Software          |
00084  | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            |
00085  +----------------------------------------------------------------------+
00086 @endverbatim
00087  *
00088  * All computation are made using the double format.
00089  *
00090  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00091  * @date   January 5, 2004  15:28
00092  * @since  Qgar 2.1.1
00093  */
00094 template
00095 <
00096   class T,
00097   template<class> class CheckingPolicy = GenImage_NoCheck
00098 >
00099 class GenConvolImage
00100 
00101   : public GenImage<T, CheckingPolicy>
00102 
00103 {
00104 // -------------------------------------------------------------------
00105 // T Y P E   D E F I N I T I O N S
00106 // -------------------------------------------------------------------
00107 public:
00108 
00109 
00110   /** @name Types */
00111   //        =====
00112   //@{
00113 
00114   /**
00115    * @brief Type of the elements stored in the pixmap.
00116    */
00117   typedef T value_type;
00118 
00119   /**
00120    * @brief Reference to qgar::GenConvolImage::value_type.
00121    */
00122   typedef value_type& reference;
00123 
00124   /**
00125    * @brief Constant reference to qgar::GenConvolImage::value_type.
00126    */
00127   typedef const value_type& const_reference;
00128 
00129   /**
00130    * @brief Pointer to qgar::GenConvolImage::value_type.
00131    */
00132   typedef value_type* pointer;
00133 
00134   /**
00135    * @brief Constant pointer to qgar::GenConvolImage::value_type.
00136    */
00137   typedef const value_type* const_pointer;
00138 
00139   //@}
00140 
00141 
00142 // -------------------------------------------------------------------
00143 // P U B L I C    M E M B E R S
00144 // -------------------------------------------------------------------
00145 public:
00146 
00147 
00148   /** @name Constructors */
00149   //        ============
00150   //@{
00151 
00152   /**
00153    * @brief Convolution of an image and a 1D mask.
00154    *
00155    * @param anImg  The image to be convolved
00156    * @param aMask  The convolution mask
00157    * @param anAxis The axis (default qgar::QGE_AXIS_X)
00158    */
00159   template
00160   <
00161     class ImageType, 
00162     template<class> class ImageCheckPolicy, 
00163     class MaskType
00164   >
00165   GenConvolImage(const GenImage<ImageType, ImageCheckPolicy>& anImg,
00166                  const GenMask1d<MaskType>& aMask,
00167                  QGEaxis anAxis);
00168 
00169   /**
00170    * @brief Convolution of an image and a 1D mask.
00171    *
00172    * Specialization of the general template constructor. 
00173    *
00174    * @param anImg  The image to be convolved
00175    * @param aMask  The convolution mask
00176    * @param anAxis The axis (default qgar::QGE_AXIS_X)
00177    */
00178   template
00179   <
00180     class ImageType, 
00181     template<class> class ImageCheckPolicy
00182   >
00183   GenConvolImage(const GenImage<ImageType, ImageCheckPolicy>& anImg,
00184                  const GenMask1d<double>& aMask,
00185                  QGEaxis anAxis);
00186 
00187   /**
00188    * @brief Convolution of an image and a 2D mask.
00189    *
00190    * Specialization of the general template constructor. 
00191    *
00192    * @param anImg  The image to be convolved
00193    * @param aMask  The convolution mask
00194    */
00195   template
00196   <
00197     class ImageType, 
00198     template<class> class ImageCheckPolicy, 
00199     class MaskType
00200   >
00201   GenConvolImage(const GenImage<ImageType, ImageCheckPolicy>& anImg,
00202                  const GenMask2d<MaskType>& aMask);
00203 
00204   /**
00205    * @brief Convolution of an image and a 2D mask.
00206    *
00207    * Specialization of the general template constructor. 
00208    *
00209    * @param anImg  The image to be convolved
00210    * @param aMask  The convolution mask
00211    */
00212   template
00213   <
00214     class ImageType, 
00215     template<class> class ImageCheckPolicy
00216   >
00217   GenConvolImage(const GenImage<ImageType, ImageCheckPolicy>& anImg,
00218                  const GenMask2d<double>& aMask);
00219 
00220   /**
00221    * @brief Copy constructor.
00222    *
00223    * @param other another instance of the class
00224    */
00225   GenConvolImage(const GenConvolImage& other);
00226 
00227   //@}
00228 
00229 
00230   /** @name Destructor */
00231   //        ==========
00232   //@{
00233 
00234   /**
00235    * @brief Virtual destructor.
00236    */
00237   virtual ~GenConvolImage();
00238 
00239   //@}
00240 
00241 
00242 // -------------------------------------------------------------------
00243 // P R O T E C T E D    M E M B E R S
00244 // -------------------------------------------------------------------
00245 protected:
00246 
00247 
00248   /** @name 1D convolutions */
00249   //        ===============
00250   //@{
00251 
00252   /**
00253    * @brief Convolve and image along X axis with a 1D mask.
00254    *
00255    * @param anImg  image to be convolved
00256    * @param aMask  1D convolution mask
00257    */
00258   template
00259   <
00260     class ImageType, 
00261     template<class> class ImageCheckPolicy
00262   >
00263   void xconvol(const GenImage<ImageType,ImageCheckPolicy>& anImg,
00264                const DMask1d& aMask);
00265 
00266 
00267   /**
00268    * @brief Convolve along Y axis with a 1D mask.
00269    *
00270    * @param anImg  image to be convolved
00271    * @param aMask  1D convolution mask
00272    */
00273   template
00274   <
00275     class ImageType, 
00276     template<class> class ImageCheckPolicy
00277   >
00278   void yconvol(const GenImage<ImageType,ImageCheckPolicy>& anImg,
00279                const DMask1d& aMask);
00280 
00281   //@}
00282 
00283 
00284   /** @name 2D convolutions */
00285   //        ===============
00286   //@{
00287 
00288   /**
00289    * @brief Convolve with a 2D mask.
00290    *
00291    * @param anImg  image to be convolved
00292    * @param aMask  2D convolution mask
00293    */
00294   template
00295   <
00296     class ImageType, 
00297     template<class> class ImageCheckPolicy
00298   >
00299   void convol(const GenImage<ImageType,ImageCheckPolicy>& anImg,
00300               const DMask2d& aMask);
00301 
00302   /**
00303    * @brief Compute the convolution of an image and a mask
00304    * for a given pixel using row and column mirroring.
00305    * 
00306    * @param img    The image to be convolved
00307    * @param mask   The mask to perform the convolution with
00308    * @param imgRow The row index of the point to apply the mask
00309    * @param imgCol The column index of the point to apply the mask
00310    */
00311   template
00312   <
00313     class ImageType,
00314     template<class> class OtherCheckPolicy
00315   >
00316   double applyMaskWithRowAndColMirroring
00317     (const GenImage<ImageType,OtherCheckPolicy>& img,
00318      const DMask2d& mask,
00319      int imgRow,
00320      int imgCol);
00321 
00322 
00323   /**
00324    * @brief Compute the convolution of an image and a mask
00325    * for a given pixel using row mirroring.
00326    * 
00327    * @param img    The image to be convolved
00328    * @param mask   The mask to perform the convolution with
00329    * @param imgRow The row index of the point to apply the mask
00330    * @param imgCol The column index of the point to apply the mask
00331    */
00332   template
00333   <
00334     class ImageType,
00335     template<class> class OtherCheckPolicy
00336   >
00337   double
00338   applyMaskWithRowMirroring
00339     (const GenImage<ImageType,OtherCheckPolicy>& img,
00340      const DMask2d mask,
00341      int imgRow,
00342      int imgCol);
00343 
00344 
00345   /**
00346    * @brief Compute the convolution of an image and a mask
00347    * for a given pixel using column mirroring.
00348    * 
00349    * @param img    The image to be convolved
00350    * @param mask   The mask to perform the convolution with
00351    * @param imgRow The row index of the point to apply the mask
00352    * @param imgCol The column index of the point to apply the mask
00353    */
00354   template
00355   <
00356     class ImageType,
00357     template<class> class OtherCheckPolicy
00358   >
00359   double
00360   applyMaskWithColMirroring(const GenImage<ImageType,OtherCheckPolicy>& img,
00361                             const DMask2d mask,
00362                             int imgRow,
00363                             int imgCol);
00364 
00365 
00366   /**
00367    * @brief Compute the convolution of an image and a mask
00368    * for a given pixel.
00369    * 
00370    * @param img    The image to be convolved
00371    * @param mask   The mask to perform the convolution with
00372    * @param imgRow The row index of the point to apply the mask
00373    * @param imgCol The column index of the point to apply the mask
00374    */
00375   template
00376   <
00377     class ImageType,
00378     template<class> class OtherCheckPolicy
00379   >
00380   double
00381   applyMask(const GenImage<ImageType,OtherCheckPolicy>& img,
00382             const DMask2d mask,
00383             int imgRow,
00384             int imgCol);
00385 
00386   //@}
00387 
00388 
00389 // -------------------------------------------------------------------
00390 // P R I V A T E    M E M B E R S
00391 // -------------------------------------------------------------------
00392 private:
00393 
00394   //
00395   /** @name Disabled */
00396   //        ========
00397   //@{
00398 
00399   /**
00400    * @brief Assignment operator.
00401    *
00402    * @param rhs an instance of the class
00403    */
00404   GenConvolImage& operator=(const GenConvolImage& rhs);
00405 
00406   //@}
00407 
00408 // -------------------------------------------------------------------
00409 }; // class GenConvolImage
00410 
00411 
00412 } // namespace qgar
00413 
00414 
00415 
00416 
00417 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00418 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00419 // I M P L E M E N T A T I O N
00420 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00421 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00422 
00423 #include <qgarlib/GenConvolImage.TCC>
00424 
00425 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00426 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00427 
00428 
00429 
00430 
00431 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00432 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00433 // P R E D E F I N E D   C O N V O L U T I O N   I M A G E   T Y P E S
00434 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00435 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00436 
00437 
00438 namespace qgar
00439 {
00440 
00441 
00442   /** @name Predefined convolution types */
00443   //        ============================
00444   //@{
00445 
00446   /**
00447    * @ingroup IMGPROC_CONVOL
00448    *
00449    * @brief Convolution of an image of integer pixels.
00450    */
00451   typedef GenConvolImage<int> IConvolImage;
00452 
00453   /**
00454    * @ingroup IMGPROC_CONVOL
00455    *
00456    * @brief Convolution of an image of <b>float</b> pixels.
00457    */
00458   typedef GenConvolImage<float> FConvolImage;
00459 
00460   /**
00461    * @ingroup IMGPROC_CONVOL
00462    *
00463    * @brief Convolution of an image of <b>double</b> pixels.
00464    *
00465    * @see qgar::ConvolImage
00466    */
00467   typedef GenConvolImage<double> DConvolImage;
00468 
00469   /**
00470    * @ingroup IMGPROC_CONVOL
00471    *
00472    * @brief Convolution of an image of <b>double</b> pixels.
00473    *
00474    * @see qgar::DConvolImage
00475    */
00476   typedef GenConvolImage<double> ConvolImage;
00477 
00478   //@}
00479 
00480 
00481 } // namespace qgar
00482 
00483 
00484 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00485 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00486 
00487 
00488 #endif /* __GENCONVOLIMAGE_H_INCLUDED__ */