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

LabeledSkeletonImage.H

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 #ifndef __LABELEDSKELETONIMAGE_H_INCLUDED__
00029 #define __LABELEDSKELETONIMAGE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   LabeledSkeletonImage.H
00034  * @brief  Header file of class qgar::LabeledSkeletonImage.
00035  *
00036  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Adlane Habed and Karl Tombre</a>
00037  * @date   July 3,  2001  16:46
00038  * @since  Qgar 1.0
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: LabeledSkeletonImage.H,v 1.23 2005/10/14 17:05:47 masini Exp $ */
00044 
00045 
00046 
00047 // STD
00048 #include <vector>
00049 // QGAR
00050 #include <qgarlib/GenImage.H>
00051 namespace qgar
00052 {
00053   // Avoid #include's when not necessary
00054   class Dist34BlackCCImage;
00055   template <class T> class GenPoint;
00056 }
00057 
00058 
00059 
00060 namespace qgar
00061 {
00062 
00063 
00064 /** 
00065  * @ingroup IMGPROC_SKEL
00066  *
00067  * @class LabeledSkeletonImage LabeledSkeletonImage.H "qgarlib/LabeledSkeletonImage.H"
00068  *
00069  * @brief Skeleton computed using the (3,4)-distance transform.
00070  *
00071  * As described by Gabriella Sanniti di Baja in
00072  * [<a href="Bibliography.html#Sanniti-di-Baja-1994">Sanniti&nbsp;di&nbsp;Baja,&nbsp;1994</a>]
00073  */
00074 class LabeledSkeletonImage
00075 
00076   : public GreyLevelImage
00077 
00078 {
00079 // -------------------------------------------------------------------
00080 // P U B L I C    M E M B E R S
00081 // -------------------------------------------------------------------
00082 public:
00083 
00084   /** @name Constructors */
00085   //        ============
00086   //@{
00087 
00088   /**
00089    * @brief Construct from given (3,4)-distance transform image.
00090    *
00091    * @param img   3-4 distance transform image
00092    *   from which the skeleton is created
00093    * @param maxPruning maximum number of peripheral rows and/or columns
00094    *   which may be missed (default <b>0</b>, no pruning)
00095    */
00096   LabeledSkeletonImage(const Dist34BlackCCImage& img, int maxPruning = 0);
00097 
00098   //@}
00099 
00100 
00101   /** @name Destructor */
00102   //        ==========
00103   //@{
00104 
00105   /**
00106    * @brief Virtual destructor.
00107    */
00108   virtual ~LabeledSkeletonImage();
00109 
00110   //@}
00111 
00112 // -------------------------------------------------------------------
00113 // P R O T E C T E D    M E M B E R S
00114 // -------------------------------------------------------------------
00115 protected:
00116 
00117   /** @name The skeleton image */
00118   //        ==================
00119   //@{
00120 
00121   /**
00122    * @brief The marker map.
00123    */
00124   unsigned char* _pixMap2;
00125 
00126   //@}
00127 
00128 // -------------------------------------------------------------------
00129 // P R I V A T E    M E M B E R S
00130 // -------------------------------------------------------------------
00131 private:
00132 
00133   //  ================================================================
00134   /** @name Auxiliaries
00135     In all subsequent labellings, neighbors are numbered as following:
00136 @verbatim
00137   2 3 4
00138   1 0 5
00139   8 7 6
00140 @endverbatim
00141     */
00142   //  ================================================================
00143   //@{
00144 
00145   /**
00146    * @brief Find parallelwise detectable skeletal pixels.
00147    */
00148   void parallelSkelet();
00149 
00150   /**
00151    * @brief Find sequentially detectable skeletal pixels.
00152    */
00153   void sequentSkelet();
00154 
00155   /**
00156    * @brief Hole filling and final thinning.
00157    */
00158   void finalThinning();
00159 
00160   /**
00161    * @brief Pruning.
00162    */
00163   void pruning(std::vector< GenPoint<int> >& myEndPoints,
00164                int maxPruning);
00165 
00166   /**
00167    * @brief Remove jaggedness.
00168    */
00169   void removeJaggedness();
00170 
00171   /**
00172    * @brief Load the right labels for a neighborhood.
00173    */
00174   void loadLabeledNeighbors(unsigned char* p, unsigned char* n);
00175 
00176   /**
00177    * @brief Load the binary image of a neighborhood.
00178    */
00179   void loadBinaryNeighbors(unsigned char* p, unsigned char* n);
00180 
00181   /**
00182    * @brief Load suitable X binary neighbors.
00183    */
00184   void loadSuitXBinary(unsigned char suitbin[], unsigned char n[]);
00185 
00186   /**
00187    * @brief Load suitable C binary neighbors.
00188    */
00189   void loadSuitCBinary(unsigned char suitbin[], unsigned char n[]);
00190 
00191   /**
00192    * @brief Number of 8-connected components in a neighborhood.
00193    */
00194   int connexityCnt(unsigned char n[]);
00195 
00196   /**
00197    * @brief Number of 4-connected components in a neighborhood.
00198    */
00199   int crossingCnt(unsigned char n[]);
00200 
00201   /**
00202    * @brief Degree of a point: Its number of marked neighbors.
00203    */
00204   int degree(unsigned char* p);
00205 
00206   /**
00207    * @brief Triple consecutive neighbors all labeled 3
00208    * (after changes all labeled 1).
00209    */
00210   int oddEvenOddLab3(unsigned char n[], int debut);
00211 
00212   /**
00213    * @brief Gradient in a 3x3 neighborhood.
00214    */
00215   void gradient(unsigned char n[], float grad[]);
00216 
00217   /**
00218    * @brief Position of maximum gradient.
00219    */
00220   int maxGradientPos1(unsigned char* p, float grad[]);
00221 
00222   /**
00223    * @brief Find, if any, second position with same maximum gradient.
00224    */
00225   int maxGradientPos2(float grad[], unsigned char* p, int indmax);
00226 
00227   /**
00228    * @brief Reduce to unit width.
00229    *
00230    * Erase marker from any marked pixel satisfying both:
00231    * - at least one odd-neighbor is not marked,
00232    * - at least a triplet of neighbors <b>(nk, nk+2, nk+5)</b>
00233    *   (<b>k</b> odd, addition modulo 8) exists such that
00234    *   <b>nk</b> and <b>nk+2</b> are marked, and <b>nk+5</b>
00235    *   is not marked.
00236    */
00237   void unitWidth(unsigned char* p, unsigned char lab[]);
00238 
00239   //@}
00240 
00241 // -------------------------------------------------------------------
00242 }; // class LabeledSkeletonImage
00243 
00244 
00245 } // namespace qgar
00246 
00247 
00248 #endif /* __LABELEDSKELETONIMAGE_H_INCLUDED__ */
00249