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