contrib/mul/vil3d/vil3d_decimate.h
Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_decimate.h
00002 #ifndef vil3d_decimate_h_
00003 #define vil3d_decimate_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott.
00010 
00011 #include <vil3d/vil3d_fwd.h>
00012 
00013 
00014 //: Create a view which is a decimated version of src.
00015 // Doesn't modify underlying data. O(1).
00016 // \relatesalso vil3d_image_view
00017 // The factor describes the number of input rows (or columns)
00018 // that are equivalent to one output.
00019 // If you don't specify the j_factor or k_factor, they will be set equal to i_factor.
00020 template<class T>
00021 inline vil3d_image_view<T> vil3d_decimate(const vil3d_image_view<T> &im,
00022   unsigned i_factor, unsigned j_factor=0, unsigned k_factor=0)
00023 {
00024   if (j_factor==0) j_factor=i_factor;
00025   if (k_factor==0) k_factor=i_factor;
00026   // use (n+d-1)/n instead of ceil((double)n/d) to calcualte sizes
00027   return vil3d_image_view<T>(
00028     im.memory_chunk(), im.origin_ptr(), (im.ni()+i_factor-1u)/i_factor,
00029     (im.nj()+j_factor-1u)/j_factor,  (im.nk()+k_factor-1u)/k_factor, im.nplanes(),
00030     im.istep()*i_factor, im.jstep()*j_factor, im.kstep()*k_factor,
00031     im.planestep() );
00032 }
00033 
00034 #endif // vil3d_decimate_h_