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

IsotropicDilatedBinaryImage.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   IsotropicDilatedBinaryImage.C
00030  * @brief  Implementation of class qgar::IsotropicDilatedBinaryImage.
00031  *
00032  *         See file IsotropicDilatedBinaryImage.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  15:46
00036  * @since  Qgar 1.0
00037  */
00038 
00039 
00040 
00041 // QGAR
00042 #include <qgarlib/GenImage.H>
00043 #include <qgarlib/IsotropicDilatedBinaryImage.H>
00044 
00045 
00046 
00047 namespace qgar
00048 {
00049 
00050 // ---------------------------------------------------------------------
00051 // C O N S T R U C T O R
00052 // ---------------------------------------------------------------------
00053 
00054 IsotropicDilatedBinaryImage::IsotropicDilatedBinaryImage(BinaryImage& aBinImg,
00055                                                          unsigned int anIterNb)
00056 
00057   : BinaryImage(aBinImg)
00058 
00059 {
00060   // Allocate tables for the rows to process
00061   BinaryImage::value_type* row1 = new BinaryImage::value_type [_width];
00062   BinaryImage::value_type* row2 = new BinaryImage::value_type [_width];
00063   BinaryImage::value_type* row3 = new BinaryImage::value_type [_width];
00064 
00065   // Allocate a table for current output row
00066   BinaryImage::value_type* orow = new BinaryImage::value_type [_width];
00067 
00068   // Create two work images
00069   BinaryImage* outputImg = new BinaryImage(aBinImg);
00070 
00071   // Loop on number of iterations
00072   for (unsigned int iCnt = 1 ; iCnt <= anIterNb ; ++iCnt)
00073     {
00074       BinaryImage* inputImg = new BinaryImage(*outputImg);  // from last iteration
00075       // No need to change the two first lines
00076       int i = 0; // current line number in input image
00077       int l = 1; // current line number in output image
00078 
00079       if ((iCnt % 2) != 0)  // 8-connexity
00080         for ( ; l < _height - 1 ; ++l, ++i)
00081           {
00082             inputImg->row(l, orow); // initialize with old values
00083 
00084             inputImg->row(i, row1); // get input values
00085             inputImg->row(i+1, row2);
00086             inputImg->row(i+2, row3);
00087 
00088             BinaryImage::value_type* q = orow + 1;
00089             int j = 1;
00090             BinaryImage::value_type* p1 = row1 + 1;
00091             BinaryImage::value_type* p2 = row2 + 1;
00092             BinaryImage::value_type* p3 = row3 + 1;
00093 
00094             for ( ; j < _width - 1 ; ++j, ++p1, ++p2, ++p3, ++q)
00095               {              // On all columns which can be processed
00096                 BinaryImage::value_type curm = *p1; // start with a point
00097                 if (*p3 > curm)
00098                   curm = *p3;
00099                 if (*p2 > curm)
00100                   curm = *p2;
00101                 if (*(p2-1) > curm)
00102                   curm = *(p2-1);
00103                 if (*(p2+1) > curm)
00104                   curm = *(p2+1);
00105 
00106                 if (*(p1-1) > curm)
00107                   curm = *(p1-1);
00108                 if (*(p1+1) > curm)
00109                   curm = *(p1+1);
00110                 if (*(p3-1) > curm)
00111                   curm = *(p3-1);
00112                 if (*(p3+1) > curm)
00113                   curm = *(p3+1);
00114 
00115                 *q = curm;
00116               }
00117 
00118             // Write result
00119             outputImg->setRow(l, orow);
00120           }
00121       else     // 4-connexity
00122         for ( ; l < _height - 1 ; ++l, ++i)
00123           {
00124             inputImg->row(l, orow); // initialize with old values
00125 
00126             inputImg->row(i,   row1); // get input values
00127             inputImg->row(i+1, row2);
00128             inputImg->row(i+2, row3);
00129 
00130             BinaryImage::value_type* q = orow + 1;
00131             int j = 1;
00132             BinaryImage::value_type* p1 = row1 + 1;
00133             BinaryImage::value_type* p2 = row2 + 1;
00134             BinaryImage::value_type* p3 = row3 + 1;
00135 
00136             for ( ; j < _width - 1 ; j++, p1++, p2++, p3++, q++)
00137               {              // On all columns which can be processed
00138                 BinaryImage::value_type curm = *p1; // start with a point
00139                 if (*p3 > curm)
00140                   curm = *p3;
00141                 if (*p2 > curm)
00142                   curm = *p2;
00143                 if (*(p2-1) > curm)
00144                   curm = *(p2-1);
00145                 if (*(p2+1) > curm)
00146                   curm = *(p2+1);
00147 
00148                 *q = curm;
00149               }
00150 
00151             // Write result
00152             outputImg->setRow(l, orow);
00153           }
00154       delete inputImg;
00155     }
00156 
00157   // Copy final result to self
00158   for (int l = 0 ; l < _height ; ++l)
00159     {
00160       outputImg->row(l, orow); // initialize with old values
00161       setRow(l, orow);
00162     }
00163 
00164   // Clean up
00165   delete [] row1;
00166   delete [] row2;
00167   delete [] row3;
00168   delete [] orow;
00169 
00170   delete outputImg;
00171 }
00172 
00173 // -------------------------------------------------------------------
00174 
00175 } // namespace qgar
00176