contrib/brl/bseg/sdet/sdet_detector.h
Go to the documentation of this file.
00001 #ifndef sdet_detector_h_
00002 #define sdet_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 sdet_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 #include <vil/vil_image_resource.h>
00080 #include <vtol/vtol_vertex_2d_sptr.h>
00081 #include <vtol/vtol_edge_2d_sptr.h>
00082 #include <vsol/vsol_digital_curve_2d.h>
00083 #include <vdgl/vdgl_digital_curve_sptr.h>
00084 #include <brip/brip_roi.h>
00085 #include "sdet_detector_params.h"
00086 
00087 class sdet_detector : public sdet_detector_params
00088 {
00089  public:
00090   // So far, not all parameters are included in the constructor.  These seem to
00091   // be the most important in controlling performance - JLM
00092   //
00093   sdet_detector(sdet_detector_params& params);
00094 
00095   sdet_detector(vil1_image, float smoothSigma = 1.0, float noiseSigma =2.0,
00096                 float contourFactor = 1.0, float junctionFactor = 1.5,
00097                 int minLength = 6, float maxGap = 2.23606, float minJump=1.0);
00098 
00099   sdet_detector(vil_image_resource_sptr &, float smoothSigma = 1.0,
00100                 float noiseSigma =2.0, float contourFactor = 1.0,
00101                 float junctionFactor = 1.5, int minLength = 6,
00102                 float maxGap = 2.23606, float minJump=1.0);
00103 
00104   ~sdet_detector();
00105 
00106   // External interfaces
00107   //Step contour detection
00108   bool DoContour();
00109 
00110   //Fold contour detection
00111   void DoFoldContourDetector(vil1_image image,
00112                              vcl_vector<vtol_edge_2d_sptr >& edgels);
00113 
00114   void DoFoldContourDetector(vil_image_resource_sptr const& image,
00115                              vcl_vector<vtol_edge_2d_sptr >& edgels);
00116 
00117 
00118   //Corner detection using curvature on edgel chains
00119   //GEOFF  void  DoCornerDetector(vil1_image image, IUPointGroup& corners);
00120 
00121   //Corner detection using curvature on edgel chains
00122   void  DoBreakCorners(vcl_vector<vtol_edge_2d_sptr >& in_edgels, vcl_vector<vtol_edge_2d_sptr >& out_edgels);
00123 
00124   // internal interfaces
00125   bool DoFoldContour();
00126   bool DoCorner( float angle = 10,      //!< smallest angle at corner
00127                  float separation = 1,  //!< |mean1-mean2|/sigma
00128                  int length = 5,        //!< min length to find cornersxo
00129                  int cycle = 2,         //!< number of corners in a cycle
00130                  int ndimension = 2);   //!< number of dimension
00131   bool DoStep();
00132   bool DoFold();
00133 
00134   gevd_bufferxy* GetBufferFromImage(); //!< vil1 image conversion
00135   gevd_bufferxy* GetBufferFromVilImage();//!< vil image conversion
00136 
00137   vcl_vector<vtol_vertex_2d_sptr> *GetVertices() {return vertices;}
00138   vcl_vector<vtol_edge_2d_sptr> *GetEdges() {return edges;}
00139 
00140   bool get_vdgl_edges(vcl_vector<vdgl_digital_curve_sptr>& edges );
00141 
00142   bool get_vsol_edges(vcl_vector<vsol_digital_curve_2d_sptr>& edges );
00143   //:The last type set is used in the execution if both types are valid
00144   void SetImage(vil1_image img);
00145   void SetImage(vil_image_resource_sptr const& img);
00146   void SetImage(vil_image_resource_sptr const& img, brip_roi const& roi);
00147 
00148   void print(vcl_ostream &strm=vcl_cout) const;
00149 
00150  protected:
00151   void ClearData(); //!< clear buffer
00152 
00153  protected:
00154   bool use_vil_image;//there could be both types set on class
00155   bool use_roi_;
00156   vil1_image image;
00157   vil_image_resource_sptr vimage;
00158   brip_roi roi_; //possible roi
00159   float noise; //!< noise estimation/threshold
00160 
00161   gevd_bufferxy *edgel,                      //!< output from DoStep
00162     *direction, *locationx, *locationy, *grad_mag, *angle; //!< detect step/fold
00163   int *junctionx, *junctiony, njunction; //!< junctions found
00164 
00165   vcl_vector<vtol_vertex_2d_sptr >* vertices;//!< network of linked
00166   vcl_vector<vtol_edge_2d_sptr >* edges; //!< edges and vertices
00167 
00168   float filterFactor;     //!< factor in convolution filter
00169   float hysteresisFactor; //!< hysteresis factor
00170   float noiseThreshold;
00171 };
00172 
00173 #endif // sdet_detector_h_