PICCANTE  0.4
The hottest HDR imaging library!
segmentation_tmo_approx.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_GL_TONE_MAPPING_SEGMENTATION_TMO_APPROX_HPP
19 #define PIC_GL_TONE_MAPPING_SEGMENTATION_TMO_APPROX_HPP
20 
21 #include "../../gl/filtering/filter_luminance.hpp"
22 #include "../../gl/filtering/filter_remove_nuked.hpp"
23 #include "../../gl/filtering/filter_iterative.hpp"
24 #include "../../gl/filtering/filter_bilateral_2ds.hpp"
25 #include "../../gl/filtering/filter_op.hpp"
26 
27 namespace pic {
28 
33 {
34 protected:
41 
42  float perCent, nLayer;
44 
45 public:
47  float minVal, maxVal;
48 
53  {
54  flt_nuked = NULL;
55  flt_lum = NULL;
56  flt_bil = NULL;
57  flt_it = NULL;
58  flt_seg = NULL;
59 
60  nLayer = 0.0f;
61  iterations = 0;
62 
63  L = NULL;
64  imgIn_flt = NULL;
65 
66  maxVal = FLT_MAX;
67  minVal = 0.0f;
68 
69  perCent = 0.005f;
70  }
71 
73  {
74  if(imgIn_flt != NULL) {
75  delete imgIn_flt;
76  imgIn_flt = NULL;
77  }
78 
79  if(L != NULL) {
80  delete L;
81  L = NULL;
82  }
83 
84  delete flt_it;
85  delete flt_bil;
86  delete flt_seg;
87  delete flt_nuked;
88  }
89 
94  void computeStatistics(Image *imgIn)
95  {
96  float nLevels, area;
97 
98  nLevels = log10f(maxVal) - log10f(minVal) + 1.0f;
99  nLayer = ((maxVal - minVal) / nLevels) / 4.0f;
100  area = imgIn->widthf * imgIn->heightf * perCent;
101  iterations = MAX(int(sqrtf(area)) / 8, 1);
102  }
103 
110  ImageGL *execute(ImageGL *imgIn, ImageGL *imgOut)
111  {
112  if(imgIn == NULL) {
113  return imgOut;
114  }
115 
116  if(!imgIn->isValid()) {
117  return imgOut;
118  }
119 
120  if(imgOut == NULL) {
121  imgOut = new ImageGL(1, imgIn->width, imgIn->height, 1, IMG_GPU, GL_TEXTURE_2D);
122  }
123 
124  //compute luminance
125  if(flt_lum == NULL) {
126  flt_lum = new FilterGLLuminance();
127  }
128 
129  L = flt_lum->Process(SingleGL(imgIn), L);
130 
131  L->getMinVal(&minVal);
132  L->getMaxVal(&maxVal);
133 
134  //iterative bilateral filtering
135  if(flt_it == NULL) {
136  flt_bil = new FilterGLBilateral2DS(1.0f, nLayer);
138  }
139 
142 
143  //threshold
144  if(flt_seg == NULL) {
145  flt_seg = FilterGLOp::CreateOpSegmentation(false, floor(log10f(minVal)));
146  }
147 
148  flt_seg->Process(SingleGL(L), L);
149 
150  //remove nuked pixels
151  if(flt_nuked == NULL) {
152  flt_nuked = new FilterGLRemoveNuked(0.9f);
153  }
154  flt_nuked->Process(SingleGL(L), imgOut);
155 
156  return imgOut;
157  }
158 };
159 
160 } // end namespace pic
161 
162 #endif /* PIC_GL_TONE_MAPPING_SEGMENTATION_TMO_APPROX_HPP */
163 
float perCent
Definition: segmentation_tmo_approx.hpp:42
void computeStatistics(Image *imgIn)
computeStatistics
Definition: segmentation_tmo_approx.hpp:94
The FilterGLRemoveNuked class.
Definition: filter_remove_nuked.hpp:29
float maxVal
Definition: segmentation_tmo_approx.hpp:47
float minVal
Definition: segmentation_tmo_approx.hpp:47
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
Definition: filter_radial_basis_function.hpp:1148
FilterGLOp * flt_seg
Definition: segmentation_tmo_approx.hpp:39
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
Definition: filter_op.hpp:28
FilterGLBilateral2DS * flt_bil
Definition: segmentation_tmo_approx.hpp:38
float heightf
Definition: image.hpp:84
The FilterGLIterative class.
Definition: filter_iterative.hpp:32
ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: filter_npasses.hpp:323
~SegmentationGL()
Definition: segmentation_tmo_approx.hpp:72
The ImageGL class.
Definition: image.hpp:42
float * getMinVal(float *ret=NULL)
getMinVal
Definition: image.hpp:431
FilterGLIterative * flt_it
Definition: segmentation_tmo_approx.hpp:37
int iterations
Definition: segmentation_tmo_approx.hpp:43
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
FilterGLRemoveNuked * flt_nuked
Definition: segmentation_tmo_approx.hpp:36
The FilterGLBilateral2DS class.
Definition: filter_bilateral_2ds.hpp:63
float nLayer
Definition: segmentation_tmo_approx.hpp:42
float * getMaxVal(float *ret=NULL)
getMaxVal
Definition: image.hpp:443
FilterGLLuminance * flt_lum
Definition: segmentation_tmo_approx.hpp:35
SegmentationGL()
SegmentationGL.
Definition: segmentation_tmo_approx.hpp:52
static FilterGLOp * CreateOpSegmentation(bool bType, float minVal)
CreateOpSegmentation.
Definition: filter_op.hpp:94
float widthf
Definition: image.hpp:84
The SegmentationGL class.
Definition: segmentation_tmo_approx.hpp:32
ImageGL * L
Definition: segmentation_tmo_approx.hpp:40
int width
Definition: filter_radial_basis_function.hpp:80
ImageGLVec stack
Definition: segmentation_tmo_approx.hpp:46
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
#define MAX(a, b)
Definition: math.hpp:73
The FilterGLLuminance class.
Definition: filter_luminance.hpp:30
ImageGL * execute(ImageGL *imgIn, ImageGL *imgOut)
execute
Definition: segmentation_tmo_approx.hpp:110
ImageGL * imgIn_flt
Definition: segmentation_tmo_approx.hpp:40
Definition: image.hpp:37
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
int height
Definition: filter_radial_basis_function.hpp:80