vil_decimate.h
Go to the documentation of this file.
1 // This is core/vil/vil_decimate.h
2 #ifndef vil_decimate_h_
3 #define vil_decimate_h_
4 //:
5 // \file
6 // \author Ian Scott.
7 
9 #include <vil/vil_image_view.h>
10 
11 
12 
13 //: Create a view which is a decimated version of src.
14 // Doesn't modify underlying data. O(1).
15 // \relatesalso vil_image_view
16 // The factor describes the number of input rows (or columns)
17 // that are equivalent to one output.
18 // If you don't specify the j_factor, it will be set equal to i_factor.
19 template<class T>
20 inline vil_image_view<T> vil_decimate(const vil_image_view<T> &im, unsigned i_factor,
21  unsigned j_factor=0)
22 {
23  if (j_factor==0) j_factor=i_factor;
24  // use (n+d-1)/n instead of ceil((double)n/d) to calcualte sizes
25  if ( i_factor == 0 ) //Silence compiler "Division by zero" warning
26  {
27  std::cerr << "ERROR: Division by 0 in " << __FILE__ << __LINE__ << std::endl;
28  throw 0;
29  }
31  (im.ni()+i_factor-1u)/i_factor, (im.nj()+j_factor-1u)/j_factor, im.nplanes(),
32  im.istep()*i_factor, im.jstep()*j_factor, im.planestep());
33 }
34 
36  unsigned j_factor=0);
37 
38 //: decimate to a region of src.
39 // \relatesalso vil_image_resource
41  unsigned i_factor, unsigned j_factor=0);
42 
43 //: A generic_image adaptor that behaves like a decimated version of its input
45 {
46  public:
48  unsigned i_factor, unsigned j_factor);
49 
50  unsigned nplanes() const override { return src_->nplanes(); }
51  unsigned ni() const override { return src_->ni() / i_factor_; }
52  unsigned nj() const override { return src_->nj() / j_factor_; }
53 
54  enum vil_pixel_format pixel_format() const override { return src_->pixel_format(); }
55 
56 
57  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
58  unsigned j0, unsigned n_j) const override;
59 
60  vil_image_view_base_sptr get_view(unsigned i0, unsigned n_i,
61  unsigned j0, unsigned n_j) const override;
62 
63 
64  bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) override;
65 
66  //: Extra property information
67  bool get_property(char const* tag, void* property_value = nullptr) const override
68  {
69  return src_->get_property(tag, property_value);
70  }
71 
72  protected:
74  unsigned i_factor_;
75  unsigned j_factor_;
76 };
77 
78 #endif // vil_decimate_h_
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
A templated smart pointer class.
Definition: vil_fwd.h:16
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_decimate.h:52
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_decimate.h:54
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
Definition: vil_decimate.h:67
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
bool put_view(const vil_image_view_base &im, unsigned i0, unsigned j0) override
Put the data in this view back into the image source.
Abstract representation of an image source or image destination.
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
A generic_image adaptor that behaves like a decimated version of its input.
Definition: vil_decimate.h:44
unsigned nplanes() const
Number of planes.
unsigned nplanes() const override
Dimensions: Planes x ni x nj.
Definition: vil_decimate.h:50
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
Representation of a generic image source or destination.
vil_decimate_image_resource(vil_image_resource_sptr const &, unsigned i_factor, unsigned j_factor)
vil_image_view< T > vil_decimate(const vil_image_view< T > &im, unsigned i_factor, unsigned j_factor=0)
Create a view which is a decimated version of src.
Definition: vil_decimate.h:20
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_decimate.h:51
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
vil_image_resource_sptr src_
Definition: vil_decimate.h:73
vil_image_view_base_sptr get_view() const
Create a read/write view of all the data.