contrib/mul/vimt/vimt_scale_pyramid_builder_2d.h
Go to the documentation of this file.
00001 // This is mul/vimt/vimt_scale_pyramid_builder_2d.h
00002 #ifndef vimt_scale_pyramid_builder_2d_h_
00003 #define vimt_scale_pyramid_builder_2d_h_
00004 //:
00005 // \file
00006 // \brief Build scale image pyramids at any scale separation
00007 // \author Ian Scott
00008 //=======================================================================
00009 
00010 #include <vimt/vimt_image_pyramid_builder.h>
00011 #include <vimt/vimt_image_2d_of.h>
00012 #include <vcl_iosfwd.h>
00013 
00014 //: Build pyramids of vimt_image_2d_of<vxl_byte> at any scale step
00015 template <class T>
00016 class vimt_scale_pyramid_builder_2d : public vimt_image_pyramid_builder
00017 {
00018   //: Minimum size in X direction of top layer of pyramid.
00019   unsigned min_x_size_;
00020 
00021   //: Minimum size in Y direction of top layer of pyramid.
00022   unsigned min_y_size_;
00023 
00024   //: Maximum levels
00025   unsigned max_levels_;
00026 
00027   //: Checks pyramid has at least n levels of correct type
00028   void checkPyr(vimt_image_pyramid& im_pyr, int n_levels) const;
00029 
00030   //: Deletes all data in im_pyr
00031   void emptyPyr(vimt_image_pyramid& im_pyr) const;
00032 
00033   //: The current scale step between pyramid levels
00034   double scale_step_;
00035 
00036  public:
00037 
00038   //: Set the minimum size of the top layer of the pyramid
00039   void set_min_size(unsigned X, unsigned Y) { min_y_size_=Y; min_x_size_=X; }
00040 
00041   //: Create new (empty) pyramid on heap.
00042   //  Caller responsible for its deletion
00043   virtual vimt_image_pyramid* new_image_pyramid() const;
00044 
00045   //: Define maximum number of levels to build.
00046   //  Limits levels built in subsequent calls to build()
00047   //  Useful efficiency measure.  As build() only takes
00048   //  a shallow copy of the original image, using
00049   //  max_l=1 avoids any copying or smoothing.
00050   virtual void set_max_levels(int max_l);
00051 
00052   //: Get the current maximum number levels allowed
00053   virtual int max_levels() const;
00054 
00055   //: Build pyramid
00056   virtual void build(vimt_image_pyramid& im_pyr, const vimt_image& im) const;
00057 
00058   //: Dflt ctor
00059   vimt_scale_pyramid_builder_2d();
00060 
00061   //: Construct with given scale_step
00062   vimt_scale_pyramid_builder_2d(double scale_step);
00063 
00064   //: Destructor
00065   ~vimt_scale_pyramid_builder_2d();
00066 
00067   //: get the current scale step;
00068   virtual double scale_step() const { return scale_step_; }
00069 
00070   //: Set the Scale step
00071   void set_scale_step(double scale_step);
00072 
00073   //: Smooth and subsample src_im to produce dest_im
00074   //  Applies an appropriate filter in x and y, then sub-samples
00075   //  at the chosen scaleStep;
00076   void scale_reduce(vimt_image_2d_of<T>& dest_im,
00077                     vimt_image_2d_of<T>const& src_im) const;
00078 
00079   //: Extend pyramid
00080   // The first layer of the pyramid must already be set.
00081   virtual void extend(vimt_image_pyramid& image_pyr) const;
00082 
00083   //: Smooth and subsample src_im to produce dest_im
00084   //  Applies 5 element FIR filter in x and y, then samples
00085   //  Assumes dest_im has sufficient data allocated
00086   void scale_reduce(T* dest_im, vcl_ptrdiff_t dest_ystep,
00087                     const T* src_im,
00088                     int src_nx, int src_ny,
00089                     int dest_nx, int dest_ny,
00090                     vcl_ptrdiff_t src_istep, vcl_ptrdiff_t src_jstep) const;
00091 
00092   vimt_image_pyramid_builder* clone() const;
00093 
00094   //: Version number for I/O
00095   short version_no() const;
00096 
00097   //: Name of the class
00098   virtual vcl_string is_a() const;
00099 
00100   //: Does the name of the class match the argument?
00101   virtual bool is_class(vcl_string const& s) const;
00102 
00103   //: Print class to os
00104   virtual void print_summary(vcl_ostream&) const;
00105 
00106   //: Save class to binary file stream
00107   virtual void b_write(vsl_b_ostream& bfs) const;
00108 
00109   //: Load class from binary file stream
00110   virtual void b_read(vsl_b_istream& bfs);
00111 };
00112 
00113 #endif // vimt_scale_pyramid_builder_2d_h_