contrib/brl/bseg/brip/brip_para_cvrg.h
Go to the documentation of this file.
00001 #ifndef brip_para_cvrg_h
00002 #define brip_para_cvrg_h
00003 //-----------------------------------------------------------------------------
00004 //:
00005 // \file
00006 // \author  Joe Mundy July 31, 1999
00007 // \brief brip_para_cvrg - Detection of parallel image features
00008 //
00009 //    A detector for parallel lines. The algorithm uses a 4 direction set
00010 //   of gradient filters (0, 45, 90, 135 degrees) to detect linear steps.
00011 //   The steps are then projected onto an accumulation array oriented
00012 //   perpendicular to the direction of the linear feature. The projection
00013 //   is carried out in each of the four orientations at each pixel, using
00014 //   the approriate gradient image.
00015 //    Parallel support is defined as the existence of two or more peaks in
00016 //   the projection array. The peaks are found by carrying out non-maximal
00017 //   suppression on the projection array. This parallel coverage is quantified
00018 //   by computing the average peak height.  If there are not at least two
00019 //   peaks, the "coverage" is defined as zero.
00020 //    The direction with maximum coverage value is determined and that
00021 //   value is inserted an output image called the cover_image.
00022 //
00023 //   The current algorithm has a performance of about 1.8*10^4 pixels/sec
00024 //   The bulk of the time is taken in doing the projections.
00025 //
00026 //
00027 // \verbatim
00028 // Modifications:
00029 //   Ported to vxl July 01, 2004
00030 //   Converted to vil October 3, 2009
00031 // \endverbatim
00032 //-----------------------------------------------------------------------------
00033 
00034 #include <brip/brip_para_cvrg_params.h>
00035 #include <vil/vil_image_view.h>
00036 #include <vil/vil_image_resource_sptr.h>
00037 #include <vil/vil_rgb.h>
00038 #include <vcl_vector.h>
00039 class brip_para_cvrg : public brip_para_cvrg_params
00040 {
00041   // PUBLIC INTERFACE----------------------------------------------------------
00042 
00043  public:
00044 
00045   // Constructors/Initializers/Destructors-------------------------------------
00046   brip_para_cvrg(float sigma = 1.0, float low = 6,
00047                  float gauss_tail = .05,
00048                  int proj_width = 7, int proj_height=1,
00049                  int sup_radius = 1,
00050                  bool verbose = true);
00051 
00052   brip_para_cvrg(brip_para_cvrg_params& pdp);
00053   ~brip_para_cvrg();
00054   void do_coverage(vil_image_resource_sptr const& image);
00055 
00056   // Data Access---------------------------------------------------------------
00057   vil_image_view<float> get_float_detection_image(const float max = 255);
00058   vil_image_view<unsigned char> get_detection_image();
00059   vil_image_view<unsigned char> get_dir_image();
00060   vil_image_view<vil_rgb<unsigned char> > get_combined_image();
00061   // Utility Methods
00062  private:
00063   void init(vil_image_resource_sptr const & image);
00064   void init_variables();
00065   void set_kernel();
00066   void smooth_image();
00067   void avg(int x, int y, vil_image_view<float> const& smooth,
00068            vil_image_view<float>& avg);
00069   void grad0(int x, int y, vil_image_view<float> const& smooth,
00070              vil_image_view<float>& grad0);
00071   void grad45(int x, int y, vil_image_view<float> const& smooth,
00072               vil_image_view<float>& grad45);
00073   void grad90(int x, int y, vil_image_view<float> const& smooth,
00074               vil_image_view<float>& grad90);
00075   void grad135(int x, int y, vil_image_view<float> const& smooth,
00076                vil_image_view<float>& grad135);
00077   void compute_gradients();
00078   float project(int x, int y, int dir, vcl_vector<float>& projection);
00079   void remove_flat_peaks(int n, vcl_vector<float>& array);
00080   void non_maximum_supress(vcl_vector<float> const& array, vcl_vector<float>& sup_array);
00081   float parallel_coverage(vcl_vector<float> const& sup_array);
00082   void compute_parallel_coverage();
00083   void compute_image(vil_image_view<float> const& data,
00084                      vil_image_view<unsigned char>& image);
00085   //
00086   // Members
00087   int proj_n_;         // Number of pixels in the projection array
00088   int width_;          // The smoothing kernel width
00089   int k_size_;         // The kernel is 2*_width+1
00090   vcl_vector<float> kernel_;      // 1-Dimensional convolution kernel of size k_size
00091 
00092   int xstart_, ystart_; // The origin of the buffer in the image
00093   int xsize_, ysize_;   // The width of the image buffer
00094   vil_image_view<float> smooth_;       // The smoothed image
00095   vil_image_view<float> avg_;       // average intensity
00096   vil_image_view<float> grad0_;       // Derivative images in 45 degree increments
00097   vil_image_view<float> grad45_;
00098   vil_image_view<float> grad90_;
00099   vil_image_view<float> grad135_;
00100   vil_image_view<float> det_;        //The resulting detector value
00101   vil_image_view<float> dir_;        //The direction of maximum detection amplitude
00102   //A memory image of the detected pattern
00103   vil_image_view<unsigned char> det_image_;
00104   //A memory image of the max pattern orientation
00105   vil_image_view<unsigned char> dir_image_;
00106   vil_image_view<float> image_; //original image converted to float
00107   vcl_vector<float> sup_proj_;     //A 1-d array for maximal suppression
00108   vcl_vector<float> proj_0_;       //1d arrays for projecting the gradient magnitude
00109   vcl_vector<float> proj_45_;
00110   vcl_vector<float> proj_90_;
00111   vcl_vector<float> proj_135_;
00112 };
00113 
00114 #endif