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

GradientLocalMaxImage.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------+
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2002  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 licence. |
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 /**
00029  * @file   GradientLocalMaxImage.C
00030  * @brief  Implementation of class qgar::GradientLocalMaxImage.
00031  *
00032  *         See file GradientLocalMaxImage.H for the interface.
00033  *
00034  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00035  * @date   July 3, 2001  16:14
00036  * @since  Qgar 1.0
00037  */
00038 
00039 
00040 
00041 // STL
00042 #include <cmath>
00043 // QGAR
00044 #include <qgarlib/AbstractGradientImage.H>
00045 #include <qgarlib/GenImage.H>
00046 #include <qgarlib/GradientLocalMaxImage.H>
00047 
00048 
00049 
00050 namespace qgar
00051 {
00052 
00053 // ----------------------------------------------------------------------
00054 // C O N S T R U C T O R
00055 // ----------------------------------------------------------------------
00056 
00057 
00058 GradientLocalMaxImage::GradientLocalMaxImage(AbstractGradientImage& aGradImg)
00059 
00060   : FloatImage(aGradImg.accessDxImg())
00061 
00062 {
00063   float* p = _pPixMap;
00064 
00065   // set first row to zero
00066   for (int jCnt = 0 ; jCnt < _width ; jCnt++)
00067     {
00068       *p++ = 0.0;
00069     }
00070 
00071   // References to derivative images
00072   const FloatImage& rDxImg = aGradImg.accessDxImg();
00073   const FloatImage& rDyImg = aGradImg.accessDyImg();
00074 
00075   // loop on all rows where we can find a local maximum
00076   for (int iCnt = 1 ; iCnt < (_height - 1) ; iCnt++)
00077     {
00078 
00079       // Set first pixel to zero
00080       *p++ = 0;
00081       
00082       // <======================= _width =======================>
00083       //
00084       // |      |             |      |      |            |      |
00085       // +------+--        ---+------+------+--        --+------+
00086       // |      |             |  px1 |      |            |      |
00087       // |      |             |      |      |            |      |
00088       // |      |             |  py1 |      |            |      |
00089       // +------+--        ---+------+------+--        --+------+
00090       // |      |             |  px2 |  px  |            |      |
00091       // |      |             |      |      |            |      |
00092       // |      |             |  py2 |  py  |            |      |
00093       // +------+--        ---+------+------+--        --+------+
00094       // |      |             |  px3 |      |            |      |
00095       // |      |             |      |      |            |      |
00096       // |      |             |  py3 |      |            |      |
00097       // +------+--        ---+------+------+--        --+------+
00098       // |      |             |      |      |            |      |
00099       //
00100       // Pointers in x derivatives image
00101       float* px1 = rDxImg.pPixMap() + (iCnt - 1) * _width;
00102       float* px2 = px1 + _width;
00103       float* px3 = px2 + _width;
00104       float* px  = px2 + 1;
00105       // Pointers in y derivatives image
00106       float* py1 = rDyImg.pPixMap() + (iCnt - 1) * _width;
00107       float* py2 = py1 + _width;
00108       float* py3 = py2 + _width;
00109       float* py  = py2 + 1;
00110 
00111       // Loop on all columns
00112       float cmp1 = 0.0;   // first value with which to compare
00113       float cmp2 = 0.0;   // second value with which to compare
00114       float mod  = 0.0;   // square of module of current point
00115 
00116       for (int jCnt = 1 ;
00117            jCnt < (_width - 1) ; 
00118            jCnt++, px1++, px2++, px3++, px++, py1++, py2++, py3++, py++)
00119         {
00120           if (fabs(*py) < (0.4142 * fabs(*px)))
00121             {
00122               //strongly horizontal gradient
00123               cmp1 = *px2 * *px2 + *py2 * *py2;
00124               cmp2 = *(px2 + 2) * *(px2 + 2) + *(py2 + 2) * *(py2 + 2);
00125             }
00126           else if (fabs(*px) < (0.4142 * fabs(*py)))
00127             {
00128               // strongly vertical gradient           
00129               cmp1 = *(px1 + 1) * *(px1 + 1) + *(py1 + 1) * *(py1 + 1);
00130               cmp2 = *(px3 + 1) * *(px3 + 1) + *(py3 + 1) * *(py3 + 1);
00131             }
00132           else if (((*px > 0.0) && (*py > 0.0)) || ((*px < 0.0) && (*py < 0.0)))
00133             {
00134               // positive diagonal -- remember direction of axes!             
00135               cmp1 = *px1 * *px1 + *py1 * *py1;
00136               cmp2 = *(px3 + 2) * *(px3 + 2) + *(py3 + 2) * *(py3 + 2);
00137             }
00138           else
00139             {
00140               // negative diagonal
00141               cmp1 = *(px1 + 2) * *(px1 + 2) + *(py1 + 2) * *(py1 + 2);
00142               cmp2 = *px3 * *px3 + *py3 * *py3;
00143             }
00144 
00145           mod = (*px) * (*px) + (*py) * (*py);
00146           if ((mod > cmp1) && (mod > cmp2))
00147             {
00148               *p++ = (float)sqrt(mod);
00149             }     
00150           else
00151             {
00152               *p++ = 0.0;
00153             }
00154         } // END for jCnt
00155       
00156       // set last pixel to zero
00157       *p++ = 0;
00158 
00159     } // END for iCnt
00160 
00161   // set last row to zero
00162   for (int jCnt = 0 ; jCnt < _width ; jCnt++)
00163     {
00164       *p++ = 0.0;
00165     }
00166 }
00167 
00168 
00169 // ----------------------------------------------------------------------
00170 
00171 
00172 } // namespace qgar