contrib/mul/mfpf/mfpf_hog_box_finder_builder.h
Go to the documentation of this file.
00001 #ifndef mfpf_hog_box_finder_builder_h_
00002 #define mfpf_hog_box_finder_builder_h_
00003 //:
00004 // \file
00005 // \brief Builder for mfpf_region_finder objects.
00006 // \author Tim Cootes
00007 
00008 #include <mfpf/mfpf_point_finder_builder.h>
00009 #include <mipa/mipa_vector_normaliser.h>
00010 #include <mfpf/mfpf_vec_cost_builder.h>
00011 #include <mbl/mbl_cloneable_ptr.h>
00012 #include <vcl_iosfwd.h>
00013 #include <mfpf/mfpf_region_form.h>
00014 
00015 
00016 //: Builder for mfpf_region_finder objects.
00017 // Text for configuring:
00018 // \verbatim
00019 // mfpf_hog_box_finder_builder { shape: ellipse { ri: 5 rj: 3  }
00020 //  vec_cost_builder: mfpf_sad_vec_cost_builder { min_mad: 1.0 }
00021 //  normaliser: mipa_ms_block_normaliser
00022   // {
00023   //   nscales: 2
00024   //   include_overall_histogram: true
00025   //   normaliser: mipa_l2norm_vector_normaliser
00026   //   ni: 16
00027   //   nj: 16
00028   //   nc_per_block: 4
00029   // }
00030 //  search_ni: 5 search_nj: 4
00031 // }
00032 // \endverbatim
00033 // Alternative for shape:
00034 // \verbatim
00035 //   shape: box { ni: 5 nj: 3 ref_x: 2.5 ref_y: 1.5 }
00036 // \endverbatim
00037 //
00038 // // Alternative for shape and block normalise:
00039 // \verbatim
00040 //   shape: box { ni: 16 nj: 16 ref_x: 8 ref_y: 8 }
00041 // 
00042 //  normaliser: mipa_ms_block_normaliser
00043   // {
00044   //   nscales: 2
00045   //   include_overall_histogram: true
00046   //   normaliser: mipa_l2norm_vector_normaliser
00047   //   ni: 16
00048   //   nj: 16
00049   //   nc_per_block: 4
00050   // }
00051 // \endverbatim
00052 
00053 class mfpf_hog_box_finder_builder : public mfpf_point_finder_builder
00054 {
00055  private:
00056   //: Kernel reference point (usually centre of sampled region [0,ni)
00057   double ref_x_;
00058   //: Kernel reference point (usually centre of sampled region) [0,nj)
00059   double ref_y_;
00060 
00061   //: Number of angle bins in histogram of orientations
00062   unsigned nA_bins_;
00063 
00064   //: When true, angles are 0-360, else 0-180
00065   bool full360_;
00066 
00067   //: Size of each cell for basic histogram is nc x nc
00068   unsigned nc_;
00069 
00070   //: Size of region is 2*ni by 2*nj cells (each cell is nc*nc)
00071   unsigned ni_;
00072   //: Size of region is 2*ni by 2*nj cells (each cell is nc*nc)
00073   unsigned nj_;
00074 
00075   //: Builder for cost model
00076   mbl_cloneable_ptr<mfpf_vec_cost_builder> cost_builder_;
00077 
00078   ////: Which normalisation to use (0=none, 1=linear)
00079   //short norm_method_;
00080 
00081   //: The normaliser
00082   mbl_cloneable_nzptr<mipa_vector_normaliser> normaliser_;
00083 
00084   //: Number of angles either side of 0 to sample at
00085   unsigned nA_;
00086 
00087   //: Angle displacement
00088   double dA_;
00089 
00090   //: Relative size of region used for estimating overlap
00091   //  If 0.5, then overlap requires pt inside central 50% of region.
00092   double overlap_f_;
00093 
00094   //: Define default values
00095   void set_defaults();
00096 
00097   //: Add one example to the model
00098   void add_one_example(const vimt_image_2d_of<float>& image,
00099                        const vgl_point_2d<double>& p,
00100                        const vgl_vector_2d<double>& u);
00101 
00102   //: Ensure any  block normaliser is consistent with region sizing, bin numbers etc
00103   void reconfigure_normaliser();
00104 
00105  public:
00106 
00107   // Dflt ctor
00108   mfpf_hog_box_finder_builder();
00109 
00110   // Destructor
00111   virtual ~mfpf_hog_box_finder_builder();
00112 
00113   //: Define number of angle bins and size of cells over which to pool
00114   //  If use360 is true, angles range [0,360), otherwise [0,180)
00115   //  (ie wrap-around occurs at 180,  5==185).
00116   void set_angle_bins(unsigned nA_bins, bool full360, unsigned cell_size);
00117 
00118   //: Define model region as an ni x nj box
00119   void set_as_box(unsigned ni, unsigned nj,
00120                   double ref_x, double ref_y,
00121                   const mfpf_vec_cost_builder& builder);
00122 
00123   //: Define model region as an ni x nj box
00124   //  Ref. point in centre.
00125   void set_as_box(unsigned ni, unsigned nj,
00126                   const mfpf_vec_cost_builder& builder);
00127 
00128   //: Define model region as an ni x nj box
00129   void set_as_box(unsigned ni, unsigned nj,
00130                   double ref_x, double ref_y);
00131 
00132   //: Define region size in world co-ordinates
00133   //  Sets up ROI to cover given box (with samples at step_size()),
00134   //  with ref point at centre.
00135   //  Currently just defines as a box
00136   virtual void set_region_size(double wi, double wj);
00137 
00138   //: Builder for PDF
00139   mfpf_vec_cost_builder& cost_builder() { return cost_builder_; }
00140 
00141   //: Create new mfpf_region_finder on heap
00142   virtual mfpf_point_finder* new_finder() const;
00143 
00144   //: Initialise building
00145   // Must be called before any calls to add_example(...)
00146   virtual void clear(unsigned n_egs);
00147 
00148   //: Add one example to the model
00149   virtual void add_example(const vimt_image_2d_of<float>& image,
00150                            const vgl_point_2d<double>& p,
00151                            const vgl_vector_2d<double>& u);
00152 
00153   //: Build object from the data supplied in add_example()
00154   virtual void build(mfpf_point_finder&);
00155 
00156   //: Initialise from a string stream
00157   virtual bool set_from_stream(vcl_istream &is);
00158 
00159   //: Name of the class
00160   virtual vcl_string is_a() const;
00161 
00162   //: Create a copy on the heap and return base class pointer
00163   virtual mfpf_point_finder_builder* clone() const;
00164 
00165   //: Print class to os
00166   virtual void print_summary(vcl_ostream& os) const;
00167 
00168   //: Prints ASCII representation of shape to os
00169   void print_shape(vcl_ostream& os) const;
00170 
00171   //: Version number for I/O
00172   short version_no() const;
00173 
00174   //: Save class to binary file stream
00175   virtual void b_write(vsl_b_ostream& bfs) const;
00176 
00177   //: Load class from binary file stream
00178   virtual void b_read(vsl_b_istream& bfs);
00179 };
00180 
00181 #endif