vil_pyramid_image_view.h
Go to the documentation of this file.
1 #ifndef vil_pyramid_image_view_h_
2 #define vil_pyramid_image_view_h_
3 //:
4 // \file
5 // \brief Representation of a pyramid hierarchy of image views.
6 // The images can be passed to the view (in this case they are any
7 // size or scale but sorted based on the scale in the descending order,
8 // or can be generated in here (default case).
9 // By default: the levels of views are half the size of the previous
10 // level and image scales are in the descending order. The biggest image
11 // is at level 0 and with scale 1.0 (1,1.0), and the next levels goes like:
12 // (1,0.5), (2,0.25) etc..
13 //
14 // \author Gamze D. Tunali
15 // \date Aug 16, 2010
16 
17 #include <vector>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21 #include <vil/vil_image_view.h>
23 
24 template <class T>
26 {
27  public:
28  //: Default constructor, creates an empty list of pyramid
30 
31  //: Creates a pyramid with one image only and its scale is set to 1.0 (biggest)
33  { images_.push_back(image); scales_.push_back(1.0); }
34 
35  //: Creates a pyramid with one image only and its scale is set to 1.0 (biggest)
37  { images_.push_back(new vil_image_view<T>(image)); scales_.push_back(1.0); }
38 
39  //: Creates a pyramid of nlevels and sets the image at the scale 1.0.
40  // It creates smaller images for the smaller scales. Each image is
41  // half the size of the previous image
43 
44  //: creates a pyramid of empty image views
45  vil_pyramid_image_view(unsigned levels, unsigned ni, unsigned nj, unsigned n_planes=1);
46 
47  //: Creates a pyramid of given image views with associated scales.
48  // post: sorted in the descending order of the scales
49  vil_pyramid_image_view(std::vector<vil_image_view_base_sptr> const& images,
50  std::vector<double> const& scales);
51 
52  //: Copy constructor.
53  // The new object will point to the same underlying image as the rhs.
55 
56  virtual ~vil_pyramid_image_view() = default;
57 
58  //: adds a view to the list of view sorted in the right place based on the scale in descending order
59  void add_view(vil_image_view_base_sptr &image, double scale);
60 
61  vil_image_view_base_sptr get_view(unsigned level, double& scale) { scale=scales_[level]; return images_[level]; }
62 
63  double scale(unsigned level){return scales_[level];}
64 
65  //: The pixel type of the images
66  typedef T pixel_type;
67 
68  void set_max_level(unsigned l) { max_levels_=l; }
69 
70  unsigned max_levels() const { return max_levels_; }
71 
72  //: Number of pyramid levels
73  unsigned nlevels() const { return nlevels_; }
74 
76 
77  vil_image_view<T>& operator()(unsigned l) { return static_cast<vil_image_view<T>&>(*images_[l]); }
78 
79  // iterators
81  inline iterator begin() { return images_[0]; }
82  inline iterator end () { return images_[images_.size()-1]; }
83 
84  protected:
85  //: the list of image vieas
86  std::vector<vil_image_view_base_sptr> images_;
87 
88  //: the associated scales of images, scales_.size() is always equals to images_.size()
89  std::vector<double> scales_;
90 
91  // the number of images in the view, 0 if it is empty
92  unsigned nlevels_;
93 
94  // this is the number of levels that cannot be exceeded, by default it is 256
95  unsigned max_levels_;
96 
97  //: returns true if the image size is < 4x4 or the max_level is reached
98  inline bool limit_reached(unsigned i, unsigned j)
99  { return i<2 || j<2 || nlevels_==max_levels_; }
100 
101  //: generates an image half the size of the given image and takes the averages
102  // of pixel values in 4x4 neighborhoods
103  void scale_down(const vil_image_view<T>&, vil_image_view_base_sptr& image_out);
104 };
105 
106 #endif
std::vector< vil_image_view_base_sptr > images_
the list of image vieas.
void add_view(vil_image_view_base_sptr &image, double scale)
adds a view to the list of view sorted in the right place based on the scale in descending order.
A base class reference-counting view of some image data.
vil_pyramid_image_view(const vil_image_view< T > &image)
Creates a pyramid with one image only and its scale is set to 1.0 (biggest).
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void scale_down(const vil_image_view< T > &, vil_image_view_base_sptr &image_out)
generates an image half the size of the given image and takes the averages.
double scale(unsigned level)
unsigned nlevels() const
Number of pyramid levels.
bool limit_reached(unsigned i, unsigned j)
returns true if the image size is < 4x4 or the max_level is reached.
virtual ~vil_pyramid_image_view()=default
std::vector< double > scales_
the associated scales of images, scales_.size() is always equals to images_.size().
vil_pyramid_image_view(vil_image_view_base_sptr image)
Creates a pyramid with one image only and its scale is set to 1.0 (biggest).
vil_image_view< T > & operator()(unsigned l)
T pixel_type
The pixel type of the images.
A base class reference-counting view of some image data.
vil_pyramid_image_view()
Default constructor, creates an empty list of pyramid.
vil_image_view_base_sptr iterator
vil_image_view_base_sptr get_view(unsigned level, double &scale)
const vil_pyramid_image_view< T > & operator=(const vil_pyramid_image_view< T > &rhs)