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

NiblackBinaryImage.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 __NIBLACKBINARYIMAGE_H_INCLUDED__
00029 #define __NIBLACKBINARYIMAGE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   NiblackBinaryImage.H
00034  * @brief  Header file of class qgar::NiblackBinaryImage.
00035  *
00036  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00037  * @date   July 3, 2001  15:01
00038  * @since  Qgar 2.0
00039  */
00040 
00041 
00042 
00043 // For RCS/CVS use: Do not delete
00044 /* $Id: NiblackBinaryImage.H,v 1.16 2005/10/14 17:05:47 masini Exp $ */
00045 
00046 
00047 
00048 // QGAR
00049 #include <qgarlib/Component.H>
00050 #include <qgarlib/GenImage.H>
00051 
00052 
00053 
00054 namespace qgar
00055 {
00056 
00057 
00058 /**
00059  * @ingroup IMGPROC_BIN
00060  *
00061  * @class NiblackBinaryImage NiblackBinaryImage.H "qgarlib/NiblackBinaryImage.H"
00062  *
00063  * @brief Binary image created by adaptive thresholding of a grey-level image.
00064  *
00065  * The thresholding is based on the method proposed by W. Niblack 
00066  * in [<a href="Bibliography.html#Niblack-1986">Niblack,&nbsp;1986</a>].
00067  * As suggested by Trier and Jain in
00068  * [<a href="Bibliography.html#Trier-and-Jain-1995">Trier&nbsp;and&nbsp;Jain,&nbsp;1995</a>],
00069  * this basic method is completed with the postprocessing step first
00070  * proposed by S.D. Yanowitz and A.M. Bruckstein in
00071  * [<a href="Bibliography.html#Yanowitz-and-Bruckstein-1989">Yanowitz&nbsp;and&nbsp;Bruckstein,&nbsp;1989</a>].
00072  *
00073  * Two extra global thresholds are used, so that adaptive binarization is
00074  * replaced by global thresholding for all pixels which are very bright
00075  * or very dark.
00076  *
00077  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00078  * @date   July 3, 200  15:01
00079  * @since  Qgar 2.0
00080  */
00081 class NiblackBinaryImage
00082 
00083   : public BinaryImage
00084 
00085 {
00086 // -------------------------------------------------------------------
00087 // T Y P E   D E F I N I T I O N S
00088 // -------------------------------------------------------------------
00089 public:
00090 
00091   /** @name Types */
00092   //        =====
00093   //@{
00094 
00095   /**
00096    * @brief Type of the elements stored in the pixel map.
00097    */
00098   typedef BinaryImage::value_type value_type;
00099 
00100   /**
00101    * @brief Reference to qgar::NiblackBinaryImage::value_type.
00102    */
00103   typedef value_type& reference;
00104 
00105   /**
00106    * @brief Constant reference to qgar::NiblackBinaryImage::value_type.
00107    */
00108   typedef const value_type& const_reference;
00109 
00110   /**
00111    * @brief Pointer to qgar::NiblackBinaryImage::value_type.
00112    */
00113   typedef value_type* pointer;
00114 
00115   /**
00116    * @brief Constant pointer to qgar::NiblackBinaryImage::value_type.
00117    */
00118   typedef const value_type* const_pointer;
00119 
00120   //@}
00121 
00122 // -------------------------------------------------------------------
00123 // P U B L I C    M E M B E R S
00124 // -------------------------------------------------------------------
00125 public:
00126 
00127   /** @name CONSTRUCTORS */
00128   //        ============
00129   //@{
00130 
00131   /**
00132    * @brief Construct from a grey-level image.
00133    *
00134    * Niblack's method itself relies on computing the local mean
00135    * <b>m</b> and the local standard deviation <b>s</b>
00136    * in a <b>aMaskSize X aMaskSize</b> neighborhood and on setting
00137    * the dynamic threshold at each point to <b>m + aK * s</b>.
00138    * The default values are those suggested by Trier and Jain.
00139    *
00140    * The postprocessing step proposed by Yanowitz and Bruckstein 
00141    * removes components for which the average gradient of the edge
00142    * pixels is below the threshold <b>aPostThres</b> (its default
00143    * value is <b>0</b>, which corresponds to no postprocessing).
00144    *
00145    * No local threshold is used if a pixel is darker than
00146    * <b>aLowThres</b> or brighter than <b>aHighThres</b>.
00147    *
00148    * @param anImg       input grey-level image
00149    * @param aLowThres   low threshold (default <b>20</b>)
00150    * @param aHighThres  high threshold (default <b>150</b>)
00151    * @param aMaskSize   mask size (default <b>15</b>)
00152    * @param aK          constant to set the dynamic threshold
00153    *                    (default <b>-0.2</b>)
00154    * @param aPostThres  postprocessing threshold (default <b>0</b>)
00155    */
00156   NiblackBinaryImage(const GreyLevelImage& anImg,
00157                      const int aLowThres = 20,
00158                      const int aHighThres = 150,
00159                      const int aMaskSize = 15,
00160                      const float aK = -0.2,
00161                      const float aPostThres = 0.0);
00162 
00163   //@}
00164 
00165 // -------------------------------------------------------------------
00166 // P R I V A T E    M E M B E R S
00167 // -------------------------------------------------------------------
00168 private:
00169 
00170   /** @name Auxiliaries */
00171   //        ===========
00172   //@{
00173 
00174   /**
00175    * @brief Get a line of labels from a component image and set pixels
00176    *   from WHITE components to <b>0</b>.
00177    *
00178    * @param aPMapCCImg  pointer to the pixel map
00179    *                    of an image of connected components
00180    * @param aBuffer     pointer to a buffer
00181    */
00182   void PRIVATEgetBlackLabels(Component::label_type* aPMapCCImg,
00183                              Component::label_type* aBuffer);
00184 
00185   //@}
00186 
00187 // -------------------------------------------------------------------
00188 }; // class NiblackBinaryImage
00189 
00190 
00191 } // namespace qgar 
00192 
00193 #endif /* __NIBLACKBINARYIMAGE_H_INCLUDED__ */