00001 // This is mul/vimt/vimt_dog_pyramid_builder_2d.h 00002 #ifndef vimt_dog_pyramid_builder_2d_h_ 00003 #define vimt_dog_pyramid_builder_2d_h_ 00004 //: 00005 // \file 00006 // \brief Build difference of gaussian pyramids of vimt_image_2d_of<T> 00007 // \author Tim Cootes 00008 00009 #include <vimt/vimt_image_2d_of.h> 00010 #include <vimt/vimt_image_pyramid_builder.h> 00011 #include <vsl/vsl_binary_io.h> 00012 #include <vcl_string.h> 00013 #include <vcl_iosfwd.h> 00014 00015 //: Build difference of gaussian pyramids of vimt_image_2d_of<T> 00016 // Computes each layer of a pyramid by smoothing 00017 // then computing the difference from the original image. 00018 // The smoothed is then subsampled using a reduction factor of 1.5 00019 // (ie each level is 2/3 the size of the level below) and 00020 // used to produced the next level. 00021 // 00022 // This is useful for finding locally interesting points and their 00023 // associated scales - see "Object Recognition from Scale Invariant Features" 00024 // D.Lowe, ICCV1999, pp.1150-1157. 00025 template <class T> 00026 class vimt_dog_pyramid_builder_2d : public vimt_image_pyramid_builder 00027 { 00028 int max_levels_; 00029 00030 mutable vimt_image_2d_of<T> work_im_; 00031 00032 //:Minimum size in X direction of top layer of pyramid. 00033 unsigned min_x_size_; 00034 00035 //:Minimum size in Y direction of top layer of pyramid. 00036 unsigned min_y_size_; 00037 00038 protected: 00039 //: Checks pyramid has at least n levels of correct type 00040 void check_pyr(vimt_image_pyramid& im_pyr, int n_levels) const; 00041 00042 //: Deletes all data in im_pyr 00043 void empty_pyr(vimt_image_pyramid& im_pyr) const; 00044 00045 public: 00046 //: Dflt ctor 00047 vimt_dog_pyramid_builder_2d(); 00048 00049 //: Destructor 00050 virtual ~vimt_dog_pyramid_builder_2d(); 00051 00052 //: Create new (empty) pyramid on heap. 00053 // Caller responsible for its deletion 00054 virtual vimt_image_pyramid* new_image_pyramid() const; 00055 00056 //: Define maximum number of levels to build. 00057 // Limits levels built in subsequent calls to build() 00058 // Useful efficiency measure. As build() only takes 00059 // a shallow copy of the original image, using 00060 // max_l=1 avoids any copying or smoothing. 00061 virtual void set_max_levels(int max_l); 00062 00063 //: Get the current maximum number levels allowed 00064 virtual int max_levels() const; 00065 00066 //: Build difference of gaussian pyramid and a gaussian pyramid 00067 // If abs_diff, then use absolute difference of gaussians 00068 void build_dog(vimt_image_pyramid& dog_pyr, 00069 vimt_image_pyramid& smooth_pyr, 00070 const vimt_image& im, bool abs_diff=true) const; 00071 00072 //: Build pyramid 00073 virtual void build(vimt_image_pyramid& dog_pyr, const vimt_image&) const; 00074 00075 //: Extend pyramid (not implemented) 00076 virtual void extend(vimt_image_pyramid&) const; 00077 00078 //: Smooth and subsample src_im to produce dest_im. 00079 // Applies filter in x and y, then samples every other pixel. 00080 // Filter width defined by set_filter_width() 00081 void gauss_reduce(const vimt_image_2d_of<T>& src_im, 00082 vimt_image_2d_of<T>& dest_im) const; 00083 00084 //: Scale step between levels 00085 virtual double scale_step() const; 00086 00087 //: Get the minimum Y size of the top layer of the pyramid. 00088 // Defaults to 5. 00089 unsigned min_y_size() const { return min_y_size_;} 00090 00091 //: Get the minimum Y size of the top layer of the pyramid. 00092 // Defaults to 5. 00093 unsigned min_x_size() const { return min_x_size_;} 00094 00095 //: Set the minimum size of the top layer of the pyramid 00096 virtual void set_min_size(unsigned X, unsigned Y) { min_y_size_ = Y; min_x_size_ = X;} 00097 00098 //: Version number for I/O 00099 short version_no() const; 00100 00101 //: Name of the class 00102 virtual vcl_string is_a() const; 00103 00104 //: Does the name of the class match the argument? 00105 virtual bool is_class(vcl_string const& s) const; 00106 00107 //: Create a copy on the heap and return base class pointer 00108 virtual vimt_image_pyramid_builder* clone() const; 00109 00110 //: Print class to os 00111 virtual void print_summary(vcl_ostream& os) const; 00112 00113 //: Save class to binary file stream 00114 virtual void b_write(vsl_b_ostream& bfs) const; 00115 00116 //: Load class from binary file stream 00117 virtual void b_read(vsl_b_istream& bfs); 00118 }; 00119 00120 #endif // vimt_dog_pyramid_builder_2d_h_