vil_pyramid_image_view.hxx
Go to the documentation of this file.
1 #ifndef vil_pyramid_image_view_hxx_
2 #define vil_pyramid_image_view_hxx_
3 
5 #include <vil/vil_image_view.h>
7 
8 template <class T>
10  unsigned nj, unsigned n_planes)
11  : nlevels_(levels), max_levels_(256)
12 {
13  images_.resize(levels);
14  scales_.resize(levels);
15  unsigned i=ni, j=nj;
16  double scale=1.0;
17  for (unsigned l=0; l<levels && !limit_reached(i,j); l++) {
18  images_[l] = new vil_image_view<T>(i, j, n_planes);
19  scales_[l] = scale;
20  i/=2;j/=2;
21  scale/=2.0;
22  }
23 }
24 
25 template <class T>
27 : nlevels_(levels), max_levels_(256)
28 {
29  vil_image_view<T>* img=dynamic_cast<vil_image_view<T>*>(image.ptr());
30  if (!img)
31  return;
32 
33  // it works with grey scale images
34  if (img->nplanes() != 1)
35  return;
36 
37  images_.resize(levels);
38  scales_.resize(levels);
39  unsigned i=image->ni()/2, j=image->nj()/2;
40  double scale=1.0;
41  images_[0] = image;
42  scales_[0] = 1.0;
43 
44  for (unsigned l=1; l<levels && !limit_reached(i,j); l++) {
45  // scale down the image
46  scale/=2.0;
47  img = static_cast<vil_image_view<T>*>(images_[l-1].ptr());
48  vil_image_view_base_sptr new_img=nullptr;
49  scale_down(*img, new_img);
50  images_[l] = new_img;
51  scales_[l] = scale;
52  i/=2;j/=2;
53  }
54 }
55 
56 template <class T>
57 vil_pyramid_image_view<T>::vil_pyramid_image_view(std::vector<vil_image_view_base_sptr> const& images,
58  std::vector<double> const& scales)
59 {
60  nlevels_=(unsigned int)(images.size());
61  images_.resize(nlevels_);
62  scales_.resize(nlevels_);
63  for (unsigned l=0; l<nlevels_; l++) {
64  images_[l] = images[l];
65  scales_[l] = scales[l];
66  }
67 }
68 
69 template <class T>
71 {
72  this->images_.resize(rhs.nlevels());
73  this->nlevels_ = rhs.nlevels();
74  this->images_ = rhs.images_;
75  this->scales_ = rhs.scales_;
76 }
77 
78 template <class T>
80 {
81  // find the place of the image based on the ordered scales
82  unsigned i=0;
83  std::vector<vil_image_view_base_sptr>::iterator image_iter=images_.begin();
84  std::vector<double>::iterator scale_iter= scales_.begin();
85  while (i<nlevels_ && scale<scales_[i]) {
86  i++;
87  image_iter++;
88  scale_iter++;
89  }
90 
91  // insert into the vector
92  images_.insert(image_iter,image);
93  scales_.insert(scale_iter,scale);
94  nlevels_++;
95 }
96 
97 template <class T>
100 {
101  this->images_.resize(rhs.nlevels());
102  this->max_levels_=rhs.max_levels();
103  this->nlevels_ = rhs.nlevels();
104  this->images_ = rhs.images_;
105  this->scales_ = rhs.scales_;
106  return *this;
107 }
108 
109 template <class T>
111  vil_image_view_base_sptr& image_out)
112 {
113  unsigned ni=image_in.ni();
114  unsigned nj=image_in.nj();
115  unsigned ni2=ni/2;
116  unsigned nj2=nj/2;
117  vil_image_view<T>* half_size = new vil_image_view<T>(ni2, nj2);
118  vil_resample_bilin(image_in, *half_size, ni2, nj2);
119  image_out = half_size;
120 }
121 
122 
123 #define VIL_PYRAMID_IMAGE_VIEW_INSTANTIATE(T) \
124 template class vil_pyramid_image_view<T >
125 
126 #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.
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.
Representation of a pyramid hierarchy of image views.
double scale(unsigned level)
Sample grid of points with bilinear interpolation in one image and place in another.
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.
std::vector< double > scales_
the associated scales of images, scales_.size() is always equals to images_.size().
unsigned ni() const
Width.
unsigned nj() const
Height.
A base class reference-counting view of some image data.
vil_pyramid_image_view()
Default constructor, creates an empty list of pyramid.
unsigned nplanes() const
Number of planes.
void vil_resample_bilin(const vil_image_view< sType > &src_image, vil_image_view< dType > &dest_image, double x0, double y0, double dx1, double dy1, double dx2, double dy2, int n1, int n2)
Sample grid of points in one image and place in another, using bilinear interpolation.
T * ptr() const
These methods all return the raw/dumb pointer.
const vil_pyramid_image_view< T > & operator=(const vil_pyramid_image_view< T > &rhs)