PICCANTE  0.4
The hottest HDR imaging library!
filter_luminance_adaptation.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_ADAPTATION_HPP
19 #define PIC_FILTERING_FILTER_LUMINANCE_ADAPTATION_HPP
20 
21 #include <cmath>
22 
23 #include "../util/math.hpp"
24 #include "../filtering/filter.hpp"
25 #include "../filtering/filter_luminance.hpp"
26 #include "../algorithms/connected_components.hpp"
27 
28 namespace pic {
29 
34 {
35 protected:
36  float threshold;
37  float bin_size_1;
38  float bin_size_2;
40  int maxLayers;
43 
44 public:
45 
52  {
53  lum = NULL;
55  }
56 
62  void update(int maxLayers = 32, float threshold = 0.05f)
63  {
64  this->threshold = threshold > 0.0f ? threshold : 0.05f;
65  this->maxLayers = maxLayers > 0 ? maxLayers : 32;
66 
67  bin_size_1 = 0.5f;
68  bin_size_2 = 2.0f;
70  }
71 
80  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
81  {
82  width = imgIn[0]->width;
83  height = imgIn[0]->height;
84  channels = 1;
85  frames = imgIn[0]->frames;
86  }
87 
94  Image *Process(ImageVec imgIn, Image *imgOut)
95  {
96  if(!checkInput(imgIn)) {
97  return imgOut;
98  }
99 
100  imgOut = setupAux(imgIn, imgOut);
101 
102  if(imgOut == NULL) {
103  return imgOut;
104  }
105 
106  lum = flt.Process(imgIn, lum);
108 
109  float lum_min;
110  lum->getMinVal(NULL, &lum_min);
111 
112  int n = imgIn[0]->width * imgIn[0]->height;
113  int *category = new int[n];
114  unsigned int *img_labels = NULL;
115 
116  imgOut->setZero();
117 
118  float maxLayer_m_1 = float(maxLayers - 1);
119 
120  for(int i = 0; i < maxLayers; i++) {
121  float bin_size = bin_size_1 + (float(i) * delta_bin_size / maxLayer_m_1);
122 
123  #pragma omp parallel for
124  for(int j = 0; j < n; j++) {
125  category[j] = int(lround((lum->data[j] - lum_min) / bin_size));
126  category[j]++;
127  }
128 
130 
131  std::vector<LabelOutput> labelsList;
132  img_labels = cc_int.execute(category, imgIn[0]->width, imgIn[0]->height, img_labels, labelsList);
133 
135 
136  ConnectedComponents<int>::reCount(img_labels, labelsList);
137 
138  for(unsigned int j_ui = 0; j_ui < labelsList.size(); j_ui++) {
139  //mean luminance
140  float La_j_ui = IndexedArrayf::mean(lum->data, labelsList[j_ui].coords);
141  IndexedArrayf::add(imgOut->data, labelsList[j_ui].coords, La_j_ui);
142  }
143  }
144  (*imgOut) /= float (maxLayers);
145 
147 
148  return imgOut;
149  }
150 };
151 
152 } // end namespace pic
153 
154 #endif /* PIC_FILTERING_FILTER_LUMINANCE_ADAPTATION_HPP */
155 
int maxLayers
Definition: filter_luminance_adaptation.hpp:40
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
float bin_size_2
Definition: filter_luminance_adaptation.hpp:38
void setZero()
setZero sets data to 0.0f.
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
PIC_INLINE long lround(double x)
lround rounds double numbers properly.
Definition: math.hpp:229
Image * Process(ImageVec imgIn, Image *imgOut)
Filter::Process.
Definition: filter_luminance_adaptation.hpp:94
FilterLuminance flt
Definition: filter_luminance_adaptation.hpp:41
The Filter class.
Definition: filter.hpp:50
PIC_INLINE float log10fPlusEpsilon(float x)
log10fPlusEpsilon
Definition: math.hpp:355
Image * lum
Definition: filter_luminance_adaptation.hpp:42
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterLuminance class.
Definition: filter_luminance.hpp:33
static void mergeIsolatedAreasWithThreshold(uint *labels, int width, int height, std::vector< LabelOutput > &labelsList, int threshold=1)
mergeIsolatedAreasWithThreshold
Definition: connected_components.hpp:577
float * getMinVal(BBox *box, float *ret)
getMinVal computes the minimum value for the current Image.
void update(int maxLayers=32, float threshold=0.05f)
update
Definition: filter_luminance_adaptation.hpp:62
The FilterLuminanceAdaptation class.
Definition: filter_luminance_adaptation.hpp:33
float threshold
Definition: filter_luminance_adaptation.hpp:36
float delta_bin_size
Definition: filter_luminance_adaptation.hpp:39
static uint * reCount(uint *imgLabel, std::vector< LabelOutput > &labelsList)
reCount
Definition: connected_components.hpp:394
FilterLuminanceAdaptation(int maxLayers=32, float threshold=0.05f)
FilterLuminanceAdaptation.
Definition: filter_luminance_adaptation.hpp:51
PIC_INLINE float powf10fMinusEpsilon(float x)
powf10fMinusEpsilon
Definition: math.hpp:365
void applyFunction(float(*func)(float))
applyFunction is an operator that applies an input function to all values in data.
float bin_size_1
Definition: filter_luminance_adaptation.hpp:37
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static void add(T *data, IntCoord &coord, T val)
add is the additive operator.
Definition: indexed_array.hpp:284
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
Definition: bilateral_separation.hpp:25
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_luminance_adaptation.hpp:80
virtual Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter.hpp:288
uint * execute(Image *imgIn, uint *imgOut, std::vector< LabelOutput > &ret)
execute
Definition: connected_components.hpp:253
int width
Definition: image.hpp:80
bool checkInput(ImageVec &imgIn)
checkInput
Definition: filter.hpp:385
int height
Definition: image.hpp:80
Definition: connected_components.hpp:78
static T mean(T *data, IntCoord &coord)
mean computes the mean value.
Definition: indexed_array.hpp:112