LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiGradientASM.h

00001 /*
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiGradientASM.h
00027  * authors ....: Benjamin Winkler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 1.3.2002
00030  * revisions ..: $Id: ltiGradientASM.h,v 1.8 2006/02/08 11:12:28 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_GRADIENT_A_S_M_H_
00034 #define _LTI_GRADIENT_A_S_M_H_
00035 
00036 #include "ltiActiveShapeModel.h"
00037 #include "ltiImage.h"
00038 #include "ltiConvolution.h"
00039 #include "ltiTriangularKernels.h"
00040 #include "ltiGaussKernels.h"
00041 
00042 namespace lti {
00043   /**
00044    * This class implements an alignment strategy for activeShapeModel (ASM).
00045    * See: Sonka's "Image Processing, Analysis, and Machine Vision", p380ff.
00046    *
00047    * For this purpose, strong gradients perpendicular to the border of a given shape are searched,
00048    * starting from each of the shapes's landmark points. The best candidate is selected by gradient
00049    * strength AND distance to the border (see parameters::weightingKernel).
00050    * The resulting shape's parameters are then adjusted to fit the underlying pointDistributionModel
00051    * (PDM) in two steps:
00052    * <ol>
00053    * <li> geometric tranformation (coarse fit)
00054    * <li> deformation (fine fit)
00055    * </ol>
00056    * The procedure is repeated, until a given number of iterations is reached.
00057    */
00058   class gradientASM : public activeShapeModel {
00059   public:
00060     /**
00061      * the parameters for the class gradientASM
00062      */
00063     class parameters : public activeShapeModel::parameters {
00064     public:
00065       /**
00066        * default constructor
00067        */
00068       parameters();
00069 
00070       /**
00071        * copy constructor
00072        * @param other the parameters object to be copied
00073        */
00074       parameters(const parameters& other);
00075 
00076       /**
00077        * destructor
00078        */
00079       ~parameters();
00080 
00081       /**
00082        * returns name of this type
00083        */
00084       const char* getTypeName() const;
00085 
00086       /**
00087        * copy the contents of a parameters object
00088        * @param other the parameters object to be copied
00089        * @return a reference to this parameters object
00090        */
00091       parameters& copy(const parameters& other);
00092 
00093       /**
00094        * copy the contents of a parameters object
00095        * @param other the parameters object to be copied
00096        * @return a reference to this parameters object
00097        */
00098       parameters& operator=(const parameters& other);
00099 
00100 
00101       /**
00102        * returns a pointer to a clone of the parameters
00103        */
00104       virtual functor::parameters* clone() const;
00105 
00106       /**
00107        * write the parameters in the given ioHandler
00108        * @param handler the ioHandler to be used
00109        * @param complete if true (the default) the enclosing begin/end will
00110        *        be also written, otherwise only the data block will be written.
00111        * @return true if write was successful
00112        */
00113       virtual bool write(ioHandler& handler,const bool complete=true) const;
00114 
00115       /**
00116        * read the parameters from the given ioHandler
00117        * @param handler the ioHandler to be used
00118        * @param complete if true (the default) the enclosing begin/end will
00119        *        be also written, otherwise only the data block will be written.
00120        * @return true if write was successful
00121        */
00122       virtual bool read(ioHandler& handler,const bool complete=true);
00123 
00124 #     ifdef _LTI_MSC_6
00125       /**
00126        * this function is required by MSVC only, as a workaround for a
00127        * very awful bug, which exists since MSVC V.4.0, and still by
00128        * V.6.0 with all bugfixes (so called "service packs") remains
00129        * there...  This method is also public due to another bug, so please
00130        * NEVER EVER call this method directly: use read() instead
00131        */
00132       bool readMS(ioHandler& handler,const bool complete=true);
00133 
00134       /**
00135        * this function is required by MSVC only, as a workaround for a
00136        * very awful bug, which exists since MSVC V.4.0, and still by
00137        * V.6.0 with all bugfixes (so called "service packs") remains
00138        * there...  This method is also public due to another bug, so please
00139        * NEVER EVER call this method directly: use write() instead
00140        */
00141       bool writeMS(ioHandler& handler,const bool complete=true) const;
00142 #     endif
00143 
00144       // ------------------------------------------------
00145       // the parameters
00146       // ------------------------------------------------
00147 
00148       /**
00149        * Kernel types for additional weigthing of feature points by distance from border:
00150        * <ul>
00151        * <li> <b>useNoKernel</b>: points are not weighted
00152        * <li> <b>useGaussKernel</b>: gradient values of searched points are weighted with a gaussian kernel, so closer points are preferred
00153        * <li> <b>useTriangularKernel</b>: gradient values of searched points are weighted with a triangular kernel
00154        * </ul>
00155        */
00156       enum eWeightingKernel {
00157         useNoKernel,
00158         useGaussKernel,
00159         useTriangularKernel
00160       };
00161 
00162 
00163       /**
00164        * defines the number of iterations for alignment.
00165        * default is 3.
00166        */
00167       int iterations;
00168 
00169       /**
00170        * defines the radius in which the next border is searched (along the normal of a point).
00171        * default is 5.
00172        */
00173       int searchExtent;
00174 
00175       /**
00176        * use value in the channel as reliability of a point in the shape
00177        * default value: false
00178        */
00179       bool gradientValueAsReliability;
00180 
00181       /**
00182        * If multiple feature points along the normal of the border are found, generally the the
00183        * Found feature points are weighted for weighting kernel for gradient values
00184        * default is a triangular kernel
00185        */
00186       eWeightingKernel weightingKernel;
00187     };
00188 
00189     /**
00190      * default constructor
00191      */
00192     gradientASM();
00193 
00194     /**
00195      * copy constructor
00196      * @param other the object to be copied
00197      */
00198     gradientASM(const gradientASM& other);
00199 
00200     /**
00201      * destructor
00202      */
00203     virtual ~gradientASM();
00204 
00205     /**
00206      * returns the name of this type ("gradientASM")
00207      */
00208     virtual const char* getTypeName() const;
00209 
00210     /**
00211      * copy data of "other" functor.
00212      * @param other the functor to be copied
00213      * @return a reference to this functor object
00214      */
00215     gradientASM& copy(const gradientASM& other);
00216 
00217     /**
00218      * alias for copy member
00219      * @param other the functor to be copied
00220      * @return a reference to this functor object
00221      */
00222     gradientASM& operator=(const gradientASM& other);
00223 
00224     /**
00225      * returns a pointer to a clone of this functor.
00226      */
00227     virtual functor* clone() const;
00228 
00229     /**
00230      * returns used parameters
00231      */
00232     const parameters& getParameters() const;
00233 
00234 
00235 
00236     /**
00237      * align shape on the given gradient channel.
00238      * iteratively, scan for closest border:
00239      * iteration process:
00240      *   the channel's values along a control point's normal are saved and afterwards weighted with the
00241      *   weighting function specified in the parameters class.
00242      *   the control point is then moved to the point with the highest value.
00243      *   the shape is then trimmed to a valid shape.
00244      * @param srcdest shape with the source data.  The result will be left here too.
00245      * @param gradientChannel gradient channel. the pdmShape is aligned along higher values in this channel.
00246      * @result a reference to the <code>srcdest</code>.
00247      */
00248     pointDistributionModel::shape& apply(pointDistributionModel::shape& srcdest, const channel &gradientChannel) const;
00249 
00250 
00251   protected:
00252 
00253     /**
00254      * align shape on the given gradient channel (no iterations!)
00255      * @return a reference to the <code>srcdest</code>.
00256      */
00257     pointDistributionModel::shape& adjustShape(pointDistributionModel::shape &srcdest,
00258                                                const channel &gradientChannel,
00259                                                fvector &pointReliability) const;
00260 
00261     /**
00262      * create weighting kernel according to parameters
00263      * return false, if no kernel was built
00264      */
00265     bool createWeightingKernel(kernel1D<float> &theKernel) const;
00266 
00267     /**
00268      * get intensity array from a channel for a specific starting point, normal and given borders
00269      */
00270     void getIntensityArray(const tpoint<float> &start, const tpoint<float> &normal, const channel &chnl, array<float> &values) const;
00271 
00272     /**
00273      * round tpoint<float> and convert to tpoint<int>
00274      */
00275     tpoint<int> roundPoint(const tpoint<float> &floatPoint) const;
00276 
00277   };
00278 }
00279 
00280 #endif

Generated on Sat Apr 10 15:25:36 2010 for LTI-Lib by Doxygen 1.6.1