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