00001 /*!@file BeoSub/CannyModel.H Simple shape models */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Zack Gossman <gossman@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/CannyModel.H $ 00035 // $Id: CannyModel.H 6990 2006-08-11 18:13:51Z rjpeters $ 00036 // 00037 00038 #ifndef CANNYMODEL_H_DEFINED 00039 #define CANNYMODEL_H_DEFINED 00040 00041 class XWindow; 00042 #include "Image/Pixels.H" 00043 #include "Image/Image.H" 00044 #include "rutz/shared_ptr.h" 00045 00046 /************************************************************************* 00047 * NOTES: 00048 * 00049 * -Poblems with threshold values: 00050 * 1) easier to get a "match" for smaller models, so the threshold should take dimensions into account (i.e. larger threshhold needed for larger models) 00051 2) The threshhold, as is, severely limits matching of partly off-image shapes. PERHAPS this could be solved by making all off-image points have a certain distance match. OR, we could change the code to IGNORE off-image points, up to a certain percentage (maybe half) 00052 * 00053 * 00054 ************************************************************************/ 00055 00056 //! The base class for shape models 00057 /*! This base class defines a basic interface by which an shape optimizer 00058 may mathematically represent a shape and get a measurement of how well 00059 the current shape matches with a Canny edge map. */ 00060 class ShapeModel { 00061 public: 00062 //! Constructor 00063 /*! Constructor 00064 @param ndims number of dimensions in the model 00065 @param thresh threshold for a shape match 00066 @param debug if true, open an XWindow and show debug drawings. */ 00067 ShapeModel(const int ndims, const double thresh, double* dims, const bool debug = false); 00068 00069 //! Destructor 00070 virtual ~ShapeModel(); 00071 00072 //! Compute distance between model (defined by p) and distance map 00073 /*! Programmer's note: calcDist() is a wrapper around getDist() 00074 which does the actual distance computation. Do not overload 00075 calcDist(), overload getDist() instead. */ 00076 double calcDist(double p[], const Image<float>& distMap) const; 00077 00078 //! Get the distance threshold 00079 double getThreshold() const; 00080 00081 //! Get the number of dimensions 00082 int getNumDims() const; 00083 00084 //! Get the dimension vector 00085 double* getDimensions() const; 00086 00087 //!Set the dimension vector 00088 void setDimensions(double* in); 00089 00090 protected: 00091 //! get distance value at one location, with optional display 00092 float getDistVal(const double x, const double y, const Image<float>& distMap, 00093 Image< PixRGB<byte> >& xdisp) const; 00094 00095 00096 //! Core of the distance computation 00097 /*! This is a pure virtual function, derived classes need to 00098 implement it. */ 00099 virtual float getDist(double p[], const Image<float>& distMap, 00100 Image< PixRGB<byte> >& xdisp) const = 0; 00101 00102 private: 00103 int itsNumDims; //!< number of dimensions describing shape 00104 double itsThreshold; //!< distance threshold for match 00105 double* itsDimensions; //!< dimesion vector for the shape model 00106 bool itsDebugMode; //!< do we want debug displays? 00107 rutz::shared_ptr<XWindow> itsWindow; //!< optional window for display 00108 00109 }; 00110 00111 00112 // ###################################################################### 00113 //! A Rectangle ShapeModel 00114 class RectangleShape : public ShapeModel { 00115 public: 00116 //! Constructor 00117 RectangleShape(const double thresh, double* dims, const bool debug = false); 00118 00119 //! Destructor 00120 virtual ~RectangleShape(); 00121 00122 protected: 00123 //! Core of the distance computation 00124 virtual float getDist(double p[], const Image<float>& distMap, 00125 Image< PixRGB<byte> >& xdisp) const; 00126 }; 00127 00128 00129 // ###################################################################### 00130 //! A Square ShapeModel 00131 00132 class SquareShape : public ShapeModel { 00133 public: 00134 //! Constructor 00135 SquareShape(const double thresh, double* dims, const bool debug = false); 00136 00137 //! Destructor 00138 virtual ~SquareShape(); 00139 00140 protected: 00141 //! Core of the distance computation 00142 virtual float getDist(double p[], const Image<float>& distMap, 00143 Image< PixRGB<byte> >& xdisp) const; 00144 }; 00145 00146 00147 // ###################################################################### 00148 //! An Octagon ShapeModel 00149 00150 class OctagonShape : public ShapeModel { 00151 public: 00152 //! Constructor 00153 OctagonShape(const double thresh, double* dims, const bool debug = false); 00154 00155 //! Destructor 00156 virtual ~OctagonShape(); 00157 00158 protected: 00159 //! Core of the distance computation 00160 virtual float getDist(double p[], const Image<float>& distMap, 00161 Image< PixRGB<byte> >& xdisp) const; 00162 }; 00163 00164 00165 // ###################################################################### 00166 //! A Circle ShapeModel 00167 00168 class CircleShape : public ShapeModel { 00169 public: 00170 //! Constructor 00171 CircleShape(const double thresh, double* dims, const bool debug = false); 00172 00173 //! Destructor 00174 virtual ~CircleShape(); 00175 00176 protected: 00177 //! Core of the distance computation 00178 virtual float getDist(double p[], const Image<float>& distMap, 00179 Image< PixRGB<byte> >& xdisp) const; 00180 }; 00181 00182 00183 // ###################################################################### 00184 //! A Parallel-lines ShapeModel 00185 class ParallelShape : public ShapeModel { 00186 public: 00187 //! Constructor 00188 ParallelShape(const double thresh, double* dims, const bool debug = false); 00189 00190 //! Destructor 00191 virtual ~ParallelShape(); 00192 00193 protected: 00194 //! Core of the distance computation 00195 virtual float getDist(double p[], const Image<float>& distMap, 00196 Image< PixRGB<byte> >& xdisp) const; 00197 }; 00198 00199 #endif 00200 00201 // ###################################################################### 00202 /* So things look consistent in everyone's emacs... */ 00203 /* Local Variables: */ 00204 /* indent-tabs-mode: nil */ 00205 /* End: */