core/vil/vil_decimate.h
Go to the documentation of this file.
00001 // This is core/vil/vil_decimate.h
00002 #ifndef vil_decimate_h_
00003 #define vil_decimate_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott.
00010 
00011 #include <vil/vil_image_resource.h>
00012 #include <vil/vil_image_view.h>
00013 
00014 
00015 
00016 //: Create a view which is a decimated version of src.
00017 // Doesn't modify underlying data. O(1).
00018 // \relatesalso vil_image_view
00019 // The factor describes the number of input rows (or columns)
00020 // that are equivalent to one output.
00021 // If you don't specify the j_factor, it will be set equal to i_factor.
00022 template<class T>
00023 inline vil_image_view<T> vil_decimate(const vil_image_view<T> &im, unsigned i_factor,
00024                                       unsigned j_factor=0)
00025 {
00026   if (j_factor==0) j_factor=i_factor;
00027   // use (n+d-1)/n instead of ceil((double)n/d) to calcualte sizes
00028   return vil_image_view<T>(im.memory_chunk(), im.top_left_ptr(),
00029                            (im.ni()+i_factor-1u)/i_factor, (im.nj()+j_factor-1u)/j_factor, im.nplanes(),
00030                            im.istep()*i_factor, im.jstep()*j_factor, im.planestep());
00031 }
00032 
00033 vil_image_view_base_sptr vil_decimate(const vil_image_view_base_sptr im, unsigned i_factor,
00034                                       unsigned j_factor=0);
00035 
00036 //: decimate to a region of src.
00037 // \relatesalso vil_image_resource
00038 vil_image_resource_sptr vil_decimate(const vil_image_resource_sptr &src,
00039                                      unsigned i_factor, unsigned j_factor=0);
00040 
00041 //: A generic_image adaptor that behaves like a decimated version of its input
00042 class vil_decimate_image_resource : public vil_image_resource
00043 {
00044  public:
00045   vil_decimate_image_resource(vil_image_resource_sptr const&,
00046                               unsigned i_factor, unsigned j_factor);
00047 
00048   virtual unsigned nplanes() const { return src_->nplanes(); }
00049   virtual unsigned ni() const { return src_->ni() / i_factor_; }
00050   virtual unsigned nj() const { return src_->nj() / j_factor_; }
00051 
00052   virtual enum vil_pixel_format pixel_format() const { return src_->pixel_format(); }
00053 
00054 
00055   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
00056                                                  unsigned j0, unsigned n_j) const;
00057 
00058   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned n_i,
00059                                             unsigned j0, unsigned n_j) const;
00060 
00061 
00062   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00063 
00064   //: Extra property information
00065   virtual bool get_property(char const* tag, void* property_value = 0) const
00066   {
00067     return src_->get_property(tag, property_value);
00068   }
00069 
00070  protected:
00071   vil_image_resource_sptr src_;
00072   unsigned i_factor_;
00073   unsigned j_factor_;
00074 };
00075 
00076 #endif // vil_decimate_h_