PICCANTE  0.4
The hottest HDR imaging library!
filter_integral_image.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_FILTERING_FILTER_INTEGRAL_IMAGE
19 #define PIC_FILTERING_FILTER_INTEGRAL_IMAGE
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 public:
31 
36  {
37  }
38 
45  Image *Process(ImageVec imgIn, Image *imgOut)
46  {
47  if(imgIn.empty()){
48  return imgOut;
49  }
50 
51  if(imgIn[0] == NULL) {
52  return imgOut;
53  }
54 
55  imgOut = setupAux(imgIn, imgOut);
56 
57  int width = imgIn[0]->width;
58  int height = imgIn[0]->height;
59  int channels = imgIn[0]->channels;
60 
61  //set up the first pixel (0,0)
62  for(int k = 0; k < channels; k++) {
63  imgOut->data[k] = imgIn[0]->data[k];
64  }
65 
66  //set up the first row
67  for(int j=1; j<width; j++) {
68  int ind1 = j * channels;
69  int ind2 = ind1 - channels;
70 
71  for(int k=0; k<channels; k++) {
72  imgOut->data[ind1 + k] = imgIn[0]->data[ind1 + k] + imgOut->data[ind2 + k];
73  }
74  }
75 
76  //set up the first column
77  int c1 = width * channels;
78  for(int i=1; i<height; i++){
79  int ind1 = i * c1;
80  int ind2 = ind1 - c1;
81  for(int k=0; k<channels; k++) {
82  imgOut->data[ind1 + k] = imgIn[0]->data[ind1 + k] + imgOut->data[ind2 + k];
83  }
84  }
85 
86  int c2 = (width + 1) * channels;
87 
88  for(int i=1; i<height; i++) {
89  int ind = i * width;
90  for(int j=1; j<width; j++) {
91  int ind1 = (ind + j) * channels;
92  int ind2 = ind1 - channels;
93  int ind3 = ind1 - c1;
94  int ind4 = ind1 - c2;
95 
96  for(int k=0; k<channels; k++) {
97  imgOut->data[ind1 + k] = imgIn[0]->data[ind1 + k] +
98  imgOut->data[ind2 + k] +
99  imgOut->data[ind3 + k] -
100  imgOut->data[ind4 + k];
101  }
102  }
103  }
104 
105  return imgOut;
106  }
107 
114  Image *ProcessP(ImageVec imgIn, Image *imgOut)
115  {
116  return Process(imgIn, imgOut);
117  }
118 };
119 
120 } // end namespace pic
121 
122 #endif /* PIC_FILTERING_FILTER_INTEGRAL_IMAGE_HPP */
FilterIntegralImage()
FilterIntegralImage.
Definition: filter_integral_image.hpp:35
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_integral_image.hpp:45
Image * ProcessP(ImageVec imgIn, Image *imgOut)
ProcessP.
Definition: filter_integral_image.hpp:114
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
The Filter class.
Definition: filter.hpp:50
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
The FilterIntegralImage class.
Definition: filter_integral_image.hpp:28
virtual Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter.hpp:288