00001 // This is mul/vimt3d/vimt3d_gaussian_pyramid_builder_3d.h 00002 #ifndef vimt3d_gaussian_pyramid_builder_3d_h_ 00003 #define vimt3d_gaussian_pyramid_builder_3d_h_ 00004 //: 00005 // \file 00006 // \brief Build Gaussian pyramids of vimt3d_image_3d_of<T> 00007 // \author Tim Cootes 00008 00009 #include <vimt3d/vimt3d_image_3d_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 vimt3d_image_3d_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 // 00020 // Note that if set_uniform_reduction(false) and width of z pixels much more 00021 // than that in x and y, then only smooth and sub-sample in x and y. 00022 // This is useful for images with non-isotropic sampling (eg MR images) 00023 // Similarly, if either x or y has significantly larger sample spacing, 00024 // the others will be smoothed first. Note, currently only works for one 00025 // dimension being significantly larger than the other two. 00026 template <class T> 00027 class vimt3d_gaussian_pyramid_builder_3d : public vimt_image_pyramid_builder 00028 { 00029 int max_levels_; 00030 00031 //: When true, subsample in x,y,z every time. 00032 // When not true and width of z pixels much more than that in x and y, 00033 // then only smooth and sub-sample in x and y 00034 bool uniform_reduction_; 00035 00036 mutable vil3d_image_view<T> work_im1_,work_im2_; 00037 00038 //: Filter width (usually 5 for a 15851 filter, or 3 for a 121 filter) 00039 unsigned filter_width_; 00040 00041 //:Minimum size in X direction of top layer of pyramid. 00042 unsigned min_x_size_; 00043 00044 //:Minimum size in Y direction of top layer of pyramid. 00045 unsigned min_y_size_; 00046 00047 //:Minimum size in Z direction of top layer of pyramid. 00048 unsigned min_z_size_; 00049 00050 protected: 00051 //: Checks pyramid has at least n levels of correct type 00052 void checkPyr(vimt_image_pyramid& im_pyr, int n_levels) const; 00053 00054 //: Deletes all data in im_pyr 00055 void emptyPyr(vimt_image_pyramid& im_pyr) const; 00056 00057 //: Select number of levels to use 00058 int n_levels(const vimt3d_image_3d_of<T>& base_image) const; 00059 00060 //: Compute real world size of pixel in image 00061 void get_pixel_size(double &dx, double& dy, double& dz, 00062 const vimt3d_image_3d_of<T>& image) const; 00063 00064 public: 00065 //: Dflt ctor 00066 vimt3d_gaussian_pyramid_builder_3d(); 00067 00068 //: Destructor 00069 virtual ~vimt3d_gaussian_pyramid_builder_3d(); 00070 00071 //: Current filter width 00072 unsigned filter_width() const { return filter_width_; } 00073 00074 //: Set current filter width (must be 5 at present) 00075 void set_filter_width(unsigned); 00076 00077 //: When true, subsample in x,y,z every time. 00078 // When not true and width of z pixels much more than that in x and y, 00079 // then only smooth and sub-sample in x and y 00080 bool uniform_reduction() const { return uniform_reduction_; } 00081 00082 //: When true, subsample in x,y,z every time. 00083 // When not true and width of z pixels much more than that in x and y, 00084 // then only smooth and sub-sample in x and y 00085 void set_uniform_reduction(bool b) { uniform_reduction_ = b; } 00086 00087 //: Create new (empty) pyramid on heap. 00088 // Caller responsible for its deletion 00089 virtual vimt_image_pyramid* new_image_pyramid() const; 00090 00091 //: Define maximum number of levels to build. 00092 // Limits levels built in subsequent calls to build() 00093 // Useful efficiency measure. As build() only takes 00094 // a shallow copy of the original image, using 00095 // max_l=1 avoids any copying or smoothing. 00096 virtual void set_max_levels(int max_l); 00097 00098 //: Get the current maximum number levels allowed 00099 virtual int max_levels() const; 00100 00101 //: Build pyramid 00102 virtual void build(vimt_image_pyramid&, const vimt_image&) const; 00103 00104 //: Extend pyramid 00105 // The first layer of the pyramid must already be set. 00106 virtual void extend(vimt_image_pyramid&) const; 00107 00108 //: Smooth and subsample src_im to produce dest_im. 00109 // Applies filter in x,y and z, then samples every other pixel. 00110 // Filter width defined by set_filter_width() 00111 void gauss_reduce(vimt3d_image_3d_of<T>& dest_im, 00112 const vimt3d_image_3d_of<T>& src_im) const; 00113 00114 //: Scale step between levels 00115 virtual double scale_step() const; 00116 00117 //: Get the minimum X size of the top layer of the pyramid. 00118 // Defaults to 5. 00119 unsigned min_x_size() const { return min_x_size_;} 00120 00121 //: Get the minimum Y size of the top layer of the pyramid. 00122 // Defaults to 5. 00123 unsigned min_y_size() const { return min_y_size_;} 00124 00125 //: Get the minimum Z size of the top layer of the pyramid. 00126 // Defaults to 5. 00127 unsigned min_z_size() const { return min_z_size_;} 00128 00129 //: Set the minimum size of the top layer of the pyramid 00130 virtual void set_min_size(unsigned X, unsigned Y, unsigned Z); 00131 00132 //: Version number for I/O 00133 short version_no() const; 00134 00135 //: Name of the class 00136 virtual vcl_string is_a() const; 00137 00138 //: Does the name of the class match the argument? 00139 virtual bool is_class(vcl_string const& s) const; 00140 00141 //: Create a copy on the heap and return base class pointer 00142 virtual vimt_image_pyramid_builder* clone() const; 00143 00144 //: Print class to os 00145 virtual void print_summary(vcl_ostream& os) const; 00146 00147 //: Save class to binary file stream 00148 virtual void b_write(vsl_b_ostream& bfs) const; 00149 00150 //: Load class from binary file stream 00151 virtual void b_read(vsl_b_istream& bfs); 00152 }; 00153 00154 #define VIMT3D_GAUSSIAN_PYRAMID_BUILDER_3D_INSTANTIATE(T) \ 00155 extern "please #include vimt3d/vimt3d_gaussian_pyramid_builder_3d.txx instead" 00156 00157 #endif // vimt3d_gaussian_pyramid_builder_3d_h_