contrib/gel/gevd/gevd_detector.h
Go to the documentation of this file.
00001 #ifndef gevd_detector_h_
00002 #define gevd_detector_h_
00003 //:
00004 // \file
00005 // \brief non-display-based interface class
00006 //
00007 // An interface to Van-Duc's Canny code. No display is involved.
00008 // The Canny has two major phases: 1) detect step edgels, 2)Follow contours
00009 // and construct a topological network. Each phase has a number of
00010 //  parameters which are defined as follows.
00011 //  Step Detection:
00012 //
00013 // - float contourFactor, junctionFactor: Scale factors for determining the
00014 //                                        gradient threshold. Nominally 1.0.
00015 //                                        contourFactor is in effect for edgels
00016 //                                        on contours (boundaries).
00017 //                                        junctionFactor is in effect during the
00018 //                                        extension of contours at endpoints.
00019 //                                        To extend contours aggressively, use a
00020 //                                        low value of junctionFactor, i.e., .5.
00021 //
00022 // - float noiseThreshold: A weighting factor that determines the relative
00023 //                         proportion of sensor noise level and texture noise level
00024 //                         as measured in a ROI in the center of the image. The
00025 //                         nominal value of -.5 gives equal weight to both. If the
00026 //                         value is positive, then a default noise threshold of 1.0
00027 //                         is assigned.
00028 //
00029 // - float filterFactor:  An overall scale factor for determining gradient threshold.
00030 //                        Nominally 2.0.
00031 //
00032 // - bool  junctionp:  If true, then recover junctions by extending contours.
00033 //                     Nominally true.
00034 //
00035 // - Contour Following:
00036 // - float hysteresisFactor:     A scale factor which is multiplied by the
00037 //                               image noise level to determine the minimum
00038 //                               gradient threshold in following an edgel contour.
00039 //                               Nominally 2.0.
00040 //
00041 // - int minLength:              The minimum length contour to constructed.
00042 //
00043 // - float minJump:              A scale factor which is multiplied by the
00044 //                               image noise level to determine the gradient
00045 //                               threshold at a junction. Nominally 1.0.
00046 //
00047 // - float maxGap:               The width of a gap which can be crossed in
00048 //                               forming a junction with another edgel contour.
00049 //                               Nominally sqrt(5) = 2.24.
00050 //
00051 // - bool spacingp:              If true, then equalize the sub-pixel locations
00052 //                               of each edgel by averaging the adjacent left
00053 //                               a right neighbor locations. Nominally true.
00054 //
00055 // - bool borderp:               If true, insert virtual contours at the border
00056 //                               to close regions. Nominally false.
00057 //
00058 // \author
00059 //             Jane S. Liu - 3/27/95
00060 //             GE Corporate Research and Development
00061 //
00062 // \verbatim
00063 //  Modifications
00064 //   JLM - May 1997
00065 //             Added extra interface for parameters not initially
00066 //             provided by Jane.These parameters are needed to get
00067 //             satisfactory boundary closure. Also expanded comments.
00068 //   JLM - November 1997
00069 //             Moved most parameters up to gevd_detectorParams in
00070 //             order to unify the use of parameters.
00071 // \endverbatim
00072 //-----------------------------------------------------------------------------
00073 
00074 class gevd_bufferxy;
00075 
00076 #include <vcl_vector.h>
00077 #include <vcl_iostream.h>
00078 #include <vil1/vil1_image.h>
00079 
00080 #include <vtol/vtol_vertex_2d_sptr.h>
00081 #include <vtol/vtol_edge_2d_sptr.h>
00082 #include <gevd/gevd_detector_params.h>
00083 
00084 class gevd_detector : public gevd_detector_params
00085 {
00086  public:
00087   // So far, not all parameters are included in the constructor.  These seem to
00088   // be the most important in controlling performance - JLM
00089   //
00090   gevd_detector(gevd_detector_params& params);
00091   gevd_detector(vil1_image, float smoothSigma = 1.0f, float noiseSigma = 2.0f,
00092                 float contourFactor = 1.0f, float junctionFactor = 1.5f,
00093                 int minLength = 6, float maxGap = 2.23606f, float minJump=1.0f);
00094   ~gevd_detector();
00095 
00096   // External interfaces
00097   //Step contour detection
00098   bool DoContour();
00099 
00100   //Fold contour detection
00101   void DoFoldContourDetector(vil1_image image, vcl_vector<vtol_edge_2d_sptr >& edgels);
00102 
00103   //Corner detection using curvature on edgel chains
00104   //GEOFF  void  DoCornerDetector(vil1_image image, IUPointGroup& corners);
00105 
00106   //Corner detection using curvature on edgel chains
00107   void  DoBreakCorners(vcl_vector<vtol_edge_2d_sptr >& in_edgels, vcl_vector<vtol_edge_2d_sptr >& out_edgels);
00108 
00109   // internal interfaces
00110   bool DoFoldContour();
00111   bool DoCorner( float angle = 10,      //!< smallest angle at corner
00112                  float separation = 1,  //!< |mean1-mean2|/sigma
00113                  int length = 5,        //!< min length to find cornersxo
00114                  int cycle = 2,         //!< number of corners in a cycle
00115                  int ndimension = 2);   //!< number of dimension
00116   bool DoStep();
00117   bool DoFold();
00118 
00119   gevd_bufferxy* GetBufferFromImage();
00120 
00121   vcl_vector<vtol_vertex_2d_sptr> *GetVertices() {return vertices;}
00122   vcl_vector<vtol_edge_2d_sptr> *GetEdges() {return edges;}
00123   void SetImage(vil1_image img);
00124 
00125   void print(vcl_ostream &strm=vcl_cout) const;
00126 
00127  protected:
00128   void UnProtectLists();
00129   void ClearData(); //!< clear buffer
00130 
00131  protected:
00132   vil1_image image;
00133   gevd_bufferxy* image_float_buf_;
00134 
00135   float noise; //!< noise estimation/threshold
00136 
00137   gevd_bufferxy *edgel,                      //!< output from DoStep
00138     *direction, *locationx, *locationy, *grad_mag, *angle; //!< detect step/fold
00139   int *junctionx, *junctiony, njunction; //!< junctions found
00140   vcl_vector<vtol_vertex_2d_sptr >* vertices; //!< network of linked edges/vertices
00141   vcl_vector<vtol_edge_2d_sptr >* edges;
00142 
00143   float filterFactor;     //!< factor in convolution filter
00144   float hysteresisFactor; //!< hysteresis factor
00145   float noiseThreshold;
00146 };
00147 
00148 #endif // gevd_detector_h_