1 #ifndef mipa_block_normaliser_h_ 2 #define mipa_block_normaliser_h_ 3 4 //: 5 // \file 6 // \author Martin Roberts 7 // \brief Class to independently normalise sub-blocks with a region 8 9 #include <string> 10 #include <iostream> 11 #include <iosfwd> 12 #ifdef _MSC_VER 13 # include <vcl_msvc_warnings.h> 14 #endif 15 #include <vnl/vnl_fwd.h> 16 #include <mbl/mbl_cloneable_ptr.h> 17 #include <mipa/mipa_vector_normaliser.h> 18 #include <mipa/mipa_identity_normaliser.h> 19 20 //: Independently normalise (non-overlapping) blocks within a region 21 // (e.g. as in simplified R-HOG without overlap) 22 23 class mipa_block_normaliser : public mipa_vector_normaliser 24 { 25 private: 26 //: The actual normaliser. 27 mbl_cloneable_nzptr<mipa_vector_normaliser> normaliser_; 28 29 protected: 30 //: Number of x cells in region 31 unsigned ni_region_; 32 //: Number of y cells in region 33 unsigned nj_region_; 34 35 //: Number of cells per block 36 unsigned nc_per_block_; 37 38 //: Number of histogram bins per cell 39 unsigned nA_; 40 41 public: 42 mipa_block_normaliser()43 mipa_block_normaliser(): 44 normaliser_(mipa_identity_normaliser()) {} 45 46 //: The actual normaliser. normaliser()47 const mipa_vector_normaliser& normaliser() const { return *normaliser_; } 48 49 //: Set the actual normaliser. set_normaliser(const mipa_vector_normaliser & norm)50 void set_normaliser(const mipa_vector_normaliser& norm) { normaliser_ = norm; } 51 52 //: Apply transform independently to each chunk of v 53 void normalise(vnl_vector<double>& v) const override; 54 55 //: Name of the class 56 std::string is_a() const override; 57 58 //: Create a copy on the heap and return base class pointer 59 mipa_vector_normaliser* clone() const override; 60 61 //: Print class to os 62 void print_summary(std::ostream& os) const override; 63 64 //: Save class to binary file stream 65 void b_write(vsl_b_ostream& bfs) const override; 66 67 //: Load class from binary file stream 68 void b_read(vsl_b_istream& bfs) override; 69 70 //: Initialise from a text stream. 71 // syntax 72 // \verbatim 73 // { 74 // normaliser: mipa_l2norm_vector_normaliser 75 // ni: 16 76 // nj: 16 77 // nA: 20; 78 // nc_per_block: 4 79 // } 80 // \endverbatim 81 void config_from_stream( 82 std::istream &is, const mbl_read_props_type &extra_props) override; 83 set_region(unsigned ni,unsigned nj)84 void set_region(unsigned ni,unsigned nj) 85 {ni_region_ = ni; nj_region_ = nj;} set_nbins(unsigned nA)86 void set_nbins(unsigned nA) 87 {nA_ = nA;} set_nc_per_block(unsigned block_size)88 void set_nc_per_block(unsigned block_size) 89 {nc_per_block_ = block_size;} 90 nA()91 unsigned nA() const {return nA_;} ni_region()92 unsigned ni_region() const {return ni_region_;} nj_region()93 unsigned nj_region() const {return nj_region_;} nc_per_block()94 unsigned nc_per_block() const {return nc_per_block_;} 95 }; 96 97 #endif // mipa_block_normaliser_h_ 98