PICCANTE  0.4
The hottest HDR imaging library!
pushpull.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_ALGORITHMS_PUSHPULL_HPP
19 #define PIC_ALGORITHMS_PUSHPULL_HPP
20 
21 #include "../image.hpp"
22 #include "../image_samplers/image_sampler_bsplines.hpp"
23 #include "../filtering/filter_down_pp.hpp"
24 #include "../filtering/filter_up_pp.hpp"
25 
26 namespace pic {
27 
31 class PushPull
32 {
33 protected:
34 
38 
42  void release() {
43  for(unsigned int i = 1; i < stack.size(); i++) {
44  if(stack[i] != NULL){
45  delete stack[i];
46  }
47  }
48 
49  stack.clear();
50  }
51 
52 public:
53 
58  {
59 
60  }
61 
63  {
64  release();
65  }
66 
72  void update(float *value, float threshold)
73  {
74  if(flt_down == NULL) {
75  flt_down = new FilterDownPP(value, threshold);
76  } else {
77  flt_down->update(value, threshold);
78  }
79 
80  if(flt_up == NULL) {
81  flt_up = new FilterUpPP(value, threshold);
82  } else {
83  flt_up->update(value, threshold);
84  }
85  }
86 
93  Image *Process(Image *imgIn, Image *imgOut)
94  {
95  if(imgIn == NULL) {
96  return imgOut;
97  }
98 
99  if(imgOut == NULL) {
100  imgOut = imgIn->clone();
101  } else {
102  *imgOut = *imgIn;
103  }
104 
105  Image *work = imgOut;
106 
107  if(stack.empty()) { //create the pyramid: Pull
108  stack.push_back(imgOut);
109 
110  while(MIN(work->width, work->height) > 1) {
111  Image *tmp = flt_down->Process(Single(work), NULL);
112 
113  if(tmp != NULL) {
114  stack.push_back(tmp);
115  work = tmp;
116  }
117  }
118  } else { //update previously created pyramid: Pull
119  int c = 1;
120  while(MIN(work->width, work->height) > 1) {
121  flt_down->Process(Double(work, stack[c]), stack[c]);
122  work = stack[c];
123  c++;
124  }
125  }
126 
127  //sample from the pyramid (stack): Push
128  int n = int(stack.size()) - 2;
129 
130  for(int i = n; i >= 0; i--) {
131  flt_up->Process(Double(stack[i + 1], stack[i]), stack[i]);
132  }
133 
134  return imgOut;
135  }
136 
144  static Image *execute(Image *img, Image *imgOut, float value)
145  {
146  PushPull pp;
147 
148  float *tmp_value = new float[img->channels];
149  for(int i = 0; i < img->channels; i++) {
150  tmp_value[i] = value;
151  }
152 
153  pp.update(tmp_value, 1e-4f);
154  imgOut = pp.Process(img, imgOut);
155 
156  delete[] tmp_value;
157 
158  return imgOut;
159  }
160 };
161 
162 } // end namespace pic
163 
164 #endif /* PIC_ALGORITHMS_PUSHPULL_HPP */
165 
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
FilterDownPP * flt_down
Definition: pushpull.hpp:35
void update(float *value, float threshold)
update
Definition: filter_up_pp.hpp:86
The PushPull class.
Definition: pushpull.hpp:31
static Image * execute(Image *img, Image *imgOut, float value)
execute
Definition: pushpull.hpp:144
PushPull()
PushPull.
Definition: pushpull.hpp:57
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
void release()
release
Definition: pushpull.hpp:42
void update(float *value, float threshold)
update
Definition: pushpull.hpp:72
The FilterUpPP class.
Definition: filter_up_pp.hpp:32
~PushPull()
Definition: pushpull.hpp:62
FilterUpPP * flt_up
Definition: pushpull.hpp:36
PIC_INLINE ImageVec Double(Image *img1, Image *img2)
Double creates an std::vector which contains img1 and img2; this is for filters input.
Definition: image_vec.hpp:49
void update(float *value, float threshold)
update
Definition: filter_down_pp.hpp:103
The FilterDownPP class.
Definition: filter_down_pp.hpp:30
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Image * clone() const
Clone creates a deep copy of the calling instance.
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
Image * Process(Image *imgIn, Image *imgOut)
process computes push-pull.
Definition: pushpull.hpp:93
ImageVec stack
Definition: pushpull.hpp:37
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80