PICCANTE  0.4
The hottest HDR imaging library!
filter_luminance.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_LUMINANCE_HPP
19 #define PIC_FILTERING_FILTER_LUMINANCE_HPP
20 
21 #include "../util/array.hpp"
22 #include "../util/std_util.hpp"
23 
24 #include "../filtering/filter.hpp"
25 
26 namespace pic {
27 
29 
33 class FilterLuminance: public Filter
34 {
35 protected:
36 
38  float *weights;
39 
46  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
47  {
48  for(int j = box->y0; j < box->y1; j++) {
49 
50  for(int i = box->x0; i < box->x1; i++) {
51 
52  float *data_src = (*src[0])(i, j);
53  float *data_dst = (*dst)(i, j);
54 
55  data_dst[0] = Arrayf::dot(data_src, weights, src[0]->channels);
56  }
57  }
58  }
59 
60 public:
61 
67  {
68  weights = NULL;
69  update(type);
70  }
71 
73  {
75  }
76 
83  static float *computeWeights(LUMINANCE_TYPE type, int channels, float *weights)
84  {
85  if(weights == NULL) {
86  weights = new float[channels];
87  }
88 
89  if(channels == 3) {
90  switch(type)
91  {
92  case LT_WARD_LUMINANCE:
93  {
94  weights[0] = 54.0f / 256.0f;
95  weights[1] = 183.0f / 256.0f;
96  weights[2] = 19.0f / 256.0f;
97  } break;
98 
99  case LT_LUMA:
100  {
101  weights[0] = 0.2989f;
102  weights[1] = 0.5870f;
103  weights[2] = 0.114f;
104  } break;
105 
106  case LT_CIE_LUMINANCE:
107  {
108  weights[0] = 0.2126f;
109  weights[1] = 0.7152f;
110  weights[2] = 0.0722f;
111  } break;
112 
113  default:
114  {
115  weights[0] = 1.0f / 3.0f;
116  weights[1] = weights[0];
117  weights[2] = weights[0];
118  }
119  }
120  } else {
121  if(channels == 1) {
122  weights[0] = 1.0f;
123  } else {
124  Arrayf::assign(1.0f / float(channels), weights, channels);
125  }
126  }
127 
128  return weights;
129  }
130 
136  {
137  this->type = type;
138  }
139 
148  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
149  {
150  width = imgIn[0]->width;
151  height = imgIn[0]->height;
152  channels = 1;
153  frames = imgIn[0]->frames;
154 
156  weights = computeWeights(type, imgIn[0]->channels, weights);
157  }
158 
167  {
168  FilterLuminance fltLum(type);
169  return fltLum.Process(Single(imgIn), imgOut);
170  }
171 };
172 
173 } // end namespace pic
174 
175 #endif /* PIC_FILTERING_FILTER_LUMINANCE_HPP */
176 
Definition: filter_luminance.hpp:28
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
LUMINANCE_TYPE
Definition: filter_luminance.hpp:28
Definition: filter_luminance.hpp:28
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
Definition: filter_luminance.hpp:28
void update(LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
update
Definition: filter_luminance.hpp:135
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_luminance.hpp:46
FilterLuminance(LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
FilterLuminance.
Definition: filter_luminance.hpp:66
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_luminance.hpp:148
int y0
Definition: bbox.hpp:32
Definition: filter_luminance.hpp:28
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
float * weights
Definition: filter_luminance.hpp:38
static T dot(T *data0, T *data1, int n)
dot
Definition: array.hpp:281
The Image class stores an image as buffer of float.
Definition: image.hpp:60
LUMINANCE_TYPE type
Definition: filter_luminance.hpp:37
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
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
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
static float * computeWeights(LUMINANCE_TYPE type, int channels, float *weights)
computeWeights
Definition: filter_luminance.hpp:83
~FilterLuminance()
Definition: filter_luminance.hpp:72