PICCANTE  0.4
The hottest HDR imaging library!
filter_gradient.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_GRADIENT_HPP
19 #define PIC_FILTERING_FILTER_GRADIENT_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
26 
30 class FilterGradient: public Filter
31 {
32 protected:
35  float mask[3];
36 
43  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
44 
45 public:
50 
57 
64 
73  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
74  {
75  width = imgIn[0]->width;
76  height = imgIn[0]->height;
77  channels = 3;
78  frames = imgIn[0]->frames;
79  }
80 
89  static Image *execute(Image *imgIn, Image *imgOut = NULL,
91  {
93  return filter.Process(Single(imgIn), imgOut);
94  }
95 };
96 
98 {
99  update(0, G_NORMAL);
100 }
101 
103  GRADIENT_TYPE type = G_NORMAL) : Filter()
104 {
106 }
107 
108 PIC_INLINE void FilterGradient::update(int colorChannel,
109  GRADIENT_TYPE type = G_NORMAL)
110 {
111  this->colorChannel = colorChannel;
112  this->type = type;
113 
114  switch(type) {
115  case G_SOBEL: {
116  mask[0] = 1.0f;
117  mask[1] = 2.0f;
118  mask[2] = 1.0f;
119  }
120  break;
121 
122  case G_PREWITT: {
123  mask[0] = 1.0f;
124  mask[1] = 1.0f;
125  mask[2] = 1.0f;
126  }
127  break;
128 
129  case G_NORMAL: {
130  mask[0] = 0.0f;
131  mask[1] = 1.0f;
132  mask[2] = 0.0f;
133  }
134  break;
135 
136  }
137 }
138 
140  BBox *box)
141 {
142  Image *img = src[0];
143 
144  int channel = (img->channels == 1) ? 0 : colorChannel;
145 
146  for(int j = box->y0; j < box->y1; j++) {
147  for(int i = box->x0; i < box->x1; i++) {
148  float gradX = 0.0f;
149  float gradY = 0.0f;
150 
151  for(int k = -1; k < 2; k++) {
152  float val = mask[k + 1];
153 
154  gradX += val * (*img)(i + 1, j + k)[channel];
155  gradX -= val * (*img)(i - 1, j + k)[channel];
156 
157  gradY += val * (*img)(i + k, j + 1)[channel];
158  gradY -= val * (*img)(i + k, j - 1)[channel];
159  }
160 
161  float *dst_data = (*dst)(i, j);
162 
163  dst_data[0] = gradX;
164  dst_data[1] = gradY;
165  dst_data[2] = sqrtf(gradX * gradX + gradY * gradY);
166  }
167  }
168 }
169 
170 } // end namespace pic
171 
172 #endif /* PIC_FILTERING_FILTER_GRADIENT_HPP */
FilterGradient()
FilterGradient.
Definition: filter_gradient.hpp:97
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_gradient.hpp:73
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
GRADIENT_TYPE type
Definition: filter_gradient.hpp:34
The Filter class.
Definition: filter.hpp:50
GRADIENT_TYPE
Definition: filter_gradient.hpp:25
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
void update(int colorChannel, GRADIENT_TYPE type)
update
Definition: filter_gradient.hpp:108
static Image * execute(Image *imgIn, Image *imgOut=NULL, GRADIENT_TYPE type=G_SOBEL, int colorChannel=0)
execute
Definition: filter_gradient.hpp:89
int y0
Definition: bbox.hpp:32
#define PIC_INLINE
Definition: base.hpp:33
int colorChannel
Definition: filter_gradient.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: filter_gradient.hpp:25
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_gradient.hpp:139
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
The FilterGradient class.
Definition: filter_gradient.hpp:30
Definition: filter_gradient.hpp:25
float mask[3]
Definition: filter_gradient.hpp:35
Definition: filter_gradient.hpp:25