PICCANTE  0.4
The hottest HDR imaging library!
filter_clahe.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_CLAHE_HPP
19 #define PIC_FILTERING_FILTER_CLAHE_HPP
20 
21 #include "../base.hpp"
22 #include "../histogram.hpp"
23 #include "../filtering/filter.hpp"
24 
25 namespace pic {
26 
30 class FilerCLAHE: public Filter
31 {
32 protected:
33  int halfSize, nBin;
35 
42  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
43  {
44  Histogram hist, hist_uni;
45  hist_uni.uniform(0.0f,
46  1.0f,
47  value, VS_LIN, nBin);
48  float *c_t = hist_uni.cumulativef(true);
49  int channels = src[0]->channels;
50 
51  for(int j = box->y0; j < box->y1; j++) {
52  for(int i = box->x0; i < box->x1; i++) {
53  float *in = (*src[0]) (i, j);
54  float *out = (*dst) (i, j);
55 
56  BBox box_ij(i - halfSize, i + halfSize, j - halfSize, j + halfSize);
57 
58  for(int ch = 0; ch < channels; ch++) {
59  hist.calculate(src[0], VS_LIN, nBin, &box_ij, ch);
60  float *c_s = hist.cumulativef(true);
61 
62  hist_uni.update(hist.getfMin(), hist.getfMax());
63 
64  int ind_source = hist.project(in[ch]);
65 
66  float x = c_s[ind_source];
67  float *ptr = std::upper_bound(c_t, c_t + nBin, x);
68  int ind_target = MAX((int)(ptr - c_t), 0);
69 
70  out[ch] = hist_uni.unproject(ind_target);
71  }
72  }
73  }
74  }
75 
76 public:
81  FilerCLAHE(int size) : Filter()
82  {
83  update(size);
84  }
85 
90  void update(int size)
91  {
92  this->halfSize = checkHalfSize(size);
93  this->nBin = 1024;//size;
94 
95  uint area = halfSize * halfSize;
96  this->value = MAX(area / nBin, 1);
97  }
98 
106  static Image *execute(Image *imgIn, Image *imgOut, int size)
107  {
108  FilerCLAHE filter(size);
109  return filter.Process(Single(imgIn), imgOut);
110  }
111 };
112 
113 } // end namespace pic
114 
115 #endif /* PIC_FILTERING_FILTER_CLAHE_HPP */
116 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
unsigned int uint
Definition: base.hpp:23
int checkHalfSize(int size)
checkHalfSize
Definition: filter_radial_basis_function.hpp:168
float * cumulativef(bool bNormalized)
cumulativef computes the cumulative Histogram.
Definition: histogram.hpp:440
void calculate(Image *imgIn, VALUE_SPACE type=VS_LIN, int nBin=256, BBox *box=NULL, int channel=0)
calculate computes the histogram of an input image. In the case of LDR images, they are ssumed to be ...
Definition: histogram.hpp:213
int halfSize
Definition: filter_clahe.hpp:33
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
The Histogram class is a class for creating, managing, loading, and saving histogram for an Image...
Definition: histogram.hpp:37
int x0
Definition: bbox.hpp:32
static Image * execute(Image *imgIn, Image *imgOut, int size)
execute
Definition: filter_clahe.hpp:106
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
float getfMin()
getfMin
Definition: histogram.hpp:468
int y0
Definition: bbox.hpp:32
FilerCLAHE(int size)
FilerCLAHE.
Definition: filter_clahe.hpp:81
int project(float x)
project converts an input value in the histogram domain.
Definition: histogram.hpp:337
uint value
Definition: filter_clahe.hpp:34
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_clahe.hpp:42
Definition: histogram.hpp:31
float unproject(int ind)
unproject converts a histogram value back to its original domain.
Definition: histogram.hpp:352
The FilerCLAHE class.
Definition: filter_clahe.hpp:30
float getfMax()
getfMax
Definition: histogram.hpp:478
The Image class stores an image as buffer of float.
Definition: image.hpp:60
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
void update(int size)
update
Definition: filter_clahe.hpp:90
#define MAX(a, b)
Definition: math.hpp:73
void uniform(float fMin, float fMax, uint value, VALUE_SPACE type, int nBin)
uniform
Definition: histogram.hpp:298
void update(float x)
update
Definition: histogram.hpp:115
int nBin
Definition: filter_clahe.hpp:33