PICCANTE  0.4
The hottest HDR imaging library!
filter_normal.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_NORMAL_HPP
19 #define PIC_FILTERING_FILTER_NORMAL_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
28 class FilterNormal: public Filter
29 {
30 protected:
32 
39  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
40 
41 public:
45  FilterNormal();
46 
52 
57  void update(int colorChannel);
58 
67  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
68  {
69  width = imgIn[0]->width;
70  height = imgIn[0]->height;
71  channels = 3;
72  frames = imgIn[0]->frames;
73  }
74 };
75 
77 {
78  update(0);
79 }
80 
82 {
84 }
85 
86 PIC_INLINE void FilterNormal::update(int colorChannel)
87 {
88  if(colorChannel<0) {
89  colorChannel = 0;
90  }
91 
92  this->colorChannel = colorChannel;
93 }
94 
96 {
97  int width = dst->width;
98  int height = dst->height;
99  int channels = src[0]->channels;
100 
101  if(colorChannel>(channels - 1)) {
102  colorChannel = 0;
103  }
104 
105  float *data = src[0]->data;
106  float gradX, gradY;
107 
108 
109  for(int j = box->y0; j < box->y1; j++) {
110  int ind = j * width;
111 
112  for(int i = box->x0; i < box->x1; i++) {
113  //Convolution kernel
114  int ind2 = (ind + i) * 3;
115 
116  //Positions
117  int ci = CLAMP(i + 1, width);
118  int cj = CLAMP(j + 1, height);
119  int ci1 = CLAMP(i - 1, width);
120  int cj1 = CLAMP(j - 1, height);
121 
122  //Grad X
123  int tmpc = (ind + ci) * channels;
124  gradX = data[tmpc + colorChannel];
125 
126  tmpc = (ind + ci1) * channels;
127  gradX -= data[tmpc + colorChannel];
128 
129  //Grad Y
130  tmpc = (cj * width + i) * channels;
131  gradY = data[tmpc + colorChannel];
132 
133  tmpc = (cj1 * width + i) * channels;
134  gradY -= data[tmpc + colorChannel];
135 
136  /*gx[0]=1.0f; gx[1]=0.0f; gx[2]=gradX;
137  gy[1]=1.0f; gy[0]=0.0f; gy[2]=gradY;
138 
139  dst->data[ind2 ] = gx[1] * gy[2] - gy[1] * gx[2];
140  dst->data[ind2+1] = gx[2] * gy[0] - gy[2] * gx[0];
141  dst->data[ind2+2] = gx[0] * gy[1] - gy[0] * gx[1];*/
142 
143  dst->data[ind2 ] = gradX;
144  dst->data[ind2 + 1] = gradY;
145  dst->data[ind2 + 2] = 1.0f;
146 
147  float norm = gradX * gradX + gradY * gradY + 1.0f;
148 
149  if(norm > 0.0f) {
150  norm = sqrtf(norm);
151  dst->data[ind2 ] /= norm;
152  dst->data[ind2 + 1] /= norm;
153  dst->data[ind2 + 2] /= norm;
154  } else {
155  dst->data[ind2 ] = 0.0f;
156  dst->data[ind2 + 1] = 0.0f;
157  dst->data[ind2 + 2] = 0.0f;
158  }
159  }
160  }
161 }
162 
163 /*
164 void genLight(float *L, int x, int y, int width, int height)
165 {
166  float xf = float(x) / float(width);
167  float yf = float(y) / float(height);
168 
169  L[0] = (xf - 0.5f) * 2.0f;
170  L[1] = (yf - 0.5f) * 2.0f;
171  L[2] = 1.0f;
172 
173  float norm = L[0] * L[0] + L[1] * L[1] + L[2] * L[2];
174 
175  if(norm > 0.0f) {
176  norm = 1.0f / sqrtf(norm);
177  L[0] *= norm;
178  L[1] *= norm;
179  L[2] *= norm;
180  };
181 };
182 */
183 
184 
185 } // end namespace pic
186 
187 #endif /* PIC_FILTERING_FILTER_NORMAL_HPP */
188 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
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
int x0
Definition: bbox.hpp:32
FilterNormal()
FilterNormal.
Definition: filter_normal.hpp:76
The Filter class.
Definition: filter.hpp:50
int colorChannel
Definition: filter_normal.hpp:31
int y0
Definition: bbox.hpp:32
The FilterNormal class.
Definition: filter_normal.hpp:28
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_normal.hpp:95
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_normal.hpp:67
void update(int colorChannel)
update
Definition: filter_normal.hpp:86