contrib/brl/bseg/sdet/sdet_nonmax_suppression.h
Go to the documentation of this file.
00001 // This is brl/bseg/sdet/sdet_nonmax_suppression.h
00002 #ifndef sdet_nonmax_suppression_h_
00003 #define sdet_nonmax_suppression_h_
00004 //---------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief a processor for non-maximal suppression
00008 // For every pixel in an image, a parabola fit is applied along the
00009 // gradient direction, and the maximum point on this parabola is used
00010 // to get the sub-pixel location of the edge. The pixel point must qualify
00011 // for being a maximum, i.e. it should have higher values than the
00012 // interpolated sub-pixels along the positive and negative gradient
00013 // direction.
00014 //
00015 // Below drawing shows the face numbers at a pixel and
00016 // is for author's own reference.
00017 //
00018 //       .---->x
00019 //       |
00020 //       |
00021 //       v y
00022 //
00023 //          6    7
00024 //        -----------
00025 //      5 |    |    | 8
00026 //        |    |    |
00027 //        -----------
00028 //      4 |    |    | 1
00029 //        |    |    |
00030 //        -----------
00031 //          3     2
00032 //
00033 // \author
00034 //  H. Can Aras - February 22, 2006
00035 //
00036 // \verbatim
00037 //  Modifications
00038 //  2006-04-08 H. Can Aras
00039 //             changed input style through the constructors, added another output variable
00040 // \endverbatim
00041 //
00042 //-------------------------------------------------------------------------
00043 #include <vcl_vector.h>
00044 #include <vsol/vsol_point_2d_sptr.h>
00045 #include <vsol/vsol_line_2d_sptr.h>
00046 #include <sdet/sdet_nonmax_suppression_params.h>
00047 #include <vgl/vgl_vector_2d.h>
00048 #include <vil/vil_image_view.h>
00049 #include <vbl/vbl_array_2d.h>
00050 #include <vgl/vgl_homg_line_2d.h>
00051 
00052 class sdet_nonmax_suppression : public sdet_nonmax_suppression_params
00053 {
00054  public:
00055   //: Constructor from a parameter block, and gradients along x and y directions given as arrays
00056   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00057                           vbl_array_2d<double> &grad_x,
00058                           vbl_array_2d<double> &grad_y);
00059   //: Constructor from a parameter block, gradient magnitudes given as an array and directions given as component arrays
00060   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00061                           vbl_array_2d<double> &dir_x,
00062                           vbl_array_2d<double> &dir_y,
00063                           vbl_array_2d<double> &grad_mag);
00064   //: Constructor from a parameter block, gradient magnitudes given as an array and the search directions
00065   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00066                           vbl_array_2d<double> &grad_mag,
00067                           vbl_array_2d<vgl_vector_2d <double> > &directions);
00068   //: Constructor from a parameter block, and gradients along x and y directions given as images
00069   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00070                           vil_image_view<double> &grad_x,
00071                           vil_image_view<double> &grad_y);
00072   //: Constructor from a parameter block, gradient magnitudes given as an image and directions given as component image
00073   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00074                           vil_image_view<double> &dir_x,
00075                           vil_image_view<double> &dir_y,
00076                           vil_image_view<double> &grad_mag);
00077   //: Constructor from a parameter block, gradient magnitudes given as an image and the search directions
00078   sdet_nonmax_suppression(sdet_nonmax_suppression_params& nsp,
00079                           vil_image_view<double> &grad_mag,
00080                           vbl_array_2d<vgl_vector_2d <double> > &directions);
00081   //: Destructor
00082   ~sdet_nonmax_suppression();
00083   //Accessors
00084   vcl_vector<vsol_point_2d_sptr>& get_points(){return points_;}
00085   vcl_vector<vsol_line_2d_sptr>& get_lines(){return lines_;}
00086   vcl_vector<vgl_vector_2d<double> >& get_directions() {return directions_;}
00087   //Utility Methods
00088   void apply();
00089   void clear();
00090 
00091  protected:
00092   //members
00093   bool points_valid_;      //process state flag
00094   vcl_vector<vsol_point_2d_sptr> points_; //output, resulting edge points
00095   vcl_vector<vsol_line_2d_sptr> lines_; //output, lines along the edges
00096   vcl_vector<vgl_vector_2d<double> > directions_; //output, direction along which non-maximal suppression was done
00097   vbl_array_2d<double> grad_x_; //Gradient in x-direction
00098   vbl_array_2d<double> grad_y_; //Gradient in y-direction
00099   vbl_array_2d<double> grad_mag_;   //Gradient magnitude
00100   int width_, height_; // Width and height of the vbl_array_2d
00101   double max_grad_mag_; //maximum gradient magnitude value
00102   int parabola_fit_type_; //flag for parabola fit method
00103   //functions
00104   int intersected_face_number(double gx, double gy);
00105   double intersection_parameter(double gx, double gy, int face_num);
00106   void f_values(int x, int y, double gx, double gy, double s, int face_num, double *f);
00107   // get the corners related to the given face
00108   void get_relative_corner_coordinates(int face_num, int *corners);
00109   // used for 3 points parabola fit
00110   double subpixel_s(double *s, double *f);
00111   // used for 9 points parabola fit
00112   double subpixel_s(int x, int y, vgl_vector_2d<double> direction);
00113   void find_distance_s_and_f_for_point(int x, int y, vgl_homg_line_2d<double> line,
00114                                        double &d, double &s, vgl_vector_2d<double> direction);
00115 };
00116 
00117 #endif // sdet_nonmax_suppression_h_