00001 // This is mul/vimt/vimt_gaussian_pyramid_builder_2d.h 00002 #ifndef vimt_gaussian_pyramid_builder_2d_h_ 00003 #define vimt_gaussian_pyramid_builder_2d_h_ 00004 //: 00005 // \file 00006 // \brief Build 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 gaussian pyramids of vimt_image_2d_of<T> 00016 // Smooth with a gaussian filter (1-5-8-5-1 by default) 00017 // and subsample so that image at level i-1 is half the 00018 // size of that at level i 00019 template <class T> 00020 class vimt_gaussian_pyramid_builder_2d : public vimt_image_pyramid_builder 00021 { 00022 int max_levels_; 00023 00024 mutable vimt_image_2d_of<T> work_im_; 00025 00026 //: Filter width (usually 5 for a 15851 filter, or 3 for a 121 filter) 00027 unsigned filter_width_; 00028 00029 //:Minimum size in X direction of top layer of pyramid. 00030 unsigned minXSize_; 00031 00032 //:Minimum size in Y direction of top layer of pyramid. 00033 unsigned minYSize_; 00034 00035 protected: 00036 //: Checks pyramid has at least n levels of correct type 00037 void check_pyr(vimt_image_pyramid& im_pyr, int n_levels) const; 00038 00039 //: Deletes all data in im_pyr 00040 void empty_pyr(vimt_image_pyramid& im_pyr) const; 00041 00042 public: 00043 //: Dflt ctor 00044 vimt_gaussian_pyramid_builder_2d(); 00045 00046 //: Destructor 00047 virtual ~vimt_gaussian_pyramid_builder_2d(); 00048 00049 //: Current filter width 00050 unsigned filter_width() const { return filter_width_; } 00051 00052 //: Set current filter width (must be 3 or 5 at present) 00053 void set_filter_width(unsigned); 00054 00055 //: Create new (empty) pyramid on heap. 00056 // Caller responsible for its deletion 00057 virtual vimt_image_pyramid* new_image_pyramid() const; 00058 00059 //: Define maximum number of levels to build. 00060 // Limits levels built in subsequent calls to build() 00061 // Useful efficiency measure. As build() only takes 00062 // a shallow copy of the original image, using 00063 // max_l=1 avoids any copying or smoothing. 00064 virtual void set_max_levels(int max_l); 00065 00066 //: Get the current maximum number levels allowed 00067 virtual int max_levels() const; 00068 00069 //: Build pyramid 00070 virtual void build(vimt_image_pyramid&, const vimt_image&) const; 00071 00072 //: Extend pyramid. 00073 // The first layer of the pyramid must already be set. 00074 // Scale steps must be equal. 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 minYSize_;} 00089 00090 //: Get the minimum X size of the top layer of the pyramid. 00091 // Defaults to 5. 00092 unsigned min_x_size() const { return minXSize_;} 00093 00094 //: Set the minimum size of the top layer of the pyramid 00095 virtual void set_min_size(unsigned X, unsigned Y) { minYSize_ = Y; minXSize_ = 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_gaussian_pyramid_builder_2d_h_