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