contrib/mul/mipa/mipa_block_normaliser.h
Go to the documentation of this file.
00001 #ifndef mipa_block_normaliser_h_
00002 #define mipa_block_normaliser_h_
00003 
00004 //:
00005 // \file
00006 // \author Martin Roberts
00007 // \brief Class to independently normalise sub-blocks with a region
00008 
00009 #include <vcl_string.h>
00010 #include <vcl_iosfwd.h>
00011 #include <vnl/vnl_fwd.h>
00012 #include <mbl/mbl_cloneable_ptr.h>
00013 #include <mipa/mipa_vector_normaliser.h>
00014 #include <mipa/mipa_identity_normaliser.h>
00015 
00016 //: Independently normalise (non-overlapping) blocks within a region
00017 //  (e.g. as in simplified R-HOG without overlap)
00018 
00019 class mipa_block_normaliser : public mipa_vector_normaliser
00020 {
00021  private:
00022   //: The actual normaliser.
00023   mbl_cloneable_nzptr<mipa_vector_normaliser> normaliser_;
00024 
00025  protected:
00026   //: Number of x cells  in region
00027   unsigned ni_region_;
00028   //: Number of y cells  in region
00029   unsigned nj_region_;
00030 
00031   //: Number of cells per block
00032   unsigned nc_per_block_;
00033 
00034   //: Number of histogram bins per cell
00035   unsigned nA_;
00036 
00037  public:
00038 
00039   mipa_block_normaliser():
00040     normaliser_(mipa_identity_normaliser()) {}
00041 
00042   //: The actual normaliser.
00043   const mipa_vector_normaliser& normaliser() const { return *normaliser_; }
00044 
00045   //: Set the actual normaliser.
00046   void set_normaliser(const mipa_vector_normaliser& norm) { normaliser_ = norm; }
00047 
00048   //: Apply transform independently to each chunk of v
00049   virtual void normalise(vnl_vector<double>& v) const;
00050 
00051   //: Name of the class
00052   virtual vcl_string is_a() const;
00053 
00054   //: Create a copy on the heap and return base class pointer
00055   virtual mipa_vector_normaliser* clone() const;
00056 
00057   //: Print class to os
00058   virtual void print_summary(vcl_ostream& os) const;
00059 
00060   //: Save class to binary file stream
00061   virtual void b_write(vsl_b_ostream& bfs) const;
00062 
00063   //: Load class from binary file stream
00064   virtual void b_read(vsl_b_istream& bfs);
00065 
00066   //: Initialise from a text stream.
00067   // syntax
00068   // \verbatim
00069   // {
00070   //   normaliser: mipa_l2norm_vector_normaliser
00071   //   ni: 16
00072   //   nj: 16
00073   //   nA: 20;
00074   //   nc_per_block: 4
00075   // }
00076   // \endverbatim
00077   virtual void config_from_stream(
00078     vcl_istream &is, const mbl_read_props_type &extra_props);
00079 
00080   void set_region(unsigned ni,unsigned nj)
00081       {ni_region_ = ni; nj_region_ = nj;}
00082   void set_nbins(unsigned nA)
00083       {nA_ = nA;}
00084   void set_nc_per_block(unsigned block_size)
00085       {nc_per_block_ = block_size;}
00086 
00087   unsigned nA() const {return nA_;}
00088   unsigned ni_region() const {return ni_region_;}
00089   unsigned nj_region() const {return nj_region_;}
00090   unsigned nc_per_block() const {return nc_per_block_;}
00091 };
00092 
00093 #endif // mipa_block_normaliser_h_