PICCANTE  0.4
The hottest HDR imaging library!
get_all_exposures.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_TONE_MAPPING_GET_ALL_EXPOSURES_HPP
19 #define PIC_TONE_MAPPING_GET_ALL_EXPOSURES_HPP
20 
21 #include "../base.hpp"
22 #include "../image.hpp"
23 #include "../histogram.hpp"
24 
25 #include "../util/math.hpp"
26 #include "../util/indexed_array.hpp"
27 
28 #include "../filtering/filter_luminance.hpp"
29 #include "../filtering/filter_simple_tmo.hpp"
30 
31 namespace pic {
32 
39 PIC_INLINE void getMinMaxFstops(Image *imgIn, int &minFstop, int &maxFstop)
40 {
41  if(imgIn == NULL) {
42  return;
43  }
44 
45  Image *img_lum = NULL;
46 
47  if(imgIn->channels == 1) {
48  img_lum = imgIn;
49  } else {
50  img_lum = FilterLuminance::execute(imgIn, NULL, LT_CIE_LUMINANCE);
51  }
52 
53  int nData = img_lum->width * img_lum->height;
54 
55  IntCoord coord;
57 
58  float commonMin = IndexedArray<float>::min(img_lum->data, coord);
59  float commonMax = IndexedArray<float>::max(img_lum->data, coord);
60 
61  float tminFstop = log2f(commonMin);
62  float tmaxFstop = log2f(commonMax);
63 
64  minFstop = int(lround(tminFstop));
65  maxFstop = int(lround(tmaxFstop));
66 
67  int halfFstops = (maxFstop - minFstop + 1) >> 1;
68  minFstop = -halfFstops + 1;
69  maxFstop = halfFstops - 1;
70 
71  if(minFstop == maxFstop) {
72  minFstop--;
73  maxFstop++;
74  }
75 
76  if(imgIn->channels != 1) {
77  delete img_lum;
78  }
79 }
80 
87 PIC_INLINE std::vector<float> getAllExposuresUniform(Image *imgIn)
88 {
89  std::vector<float> ret;
90 
91  int iMin, iMax;
92  getMinMaxFstops(imgIn, iMin, iMax);
93 
94  for(int i = iMin; i <= iMax; i++) {
95  ret.push_back(float(i));
96  }
97 
98  return ret;
99 }
100 
107 PIC_INLINE std::vector<float> getAllExposures(Image *imgIn) {
108  std::vector<float> fstops;
109 
110  if(imgIn == NULL) {
111  return fstops;
112  }
113 
114  if(!imgIn->isValid()) {
115  return fstops;
116  }
117 
118  Image *lum = NULL;
119 
120  if(imgIn->channels == 1) {
121  lum = imgIn;
122  } else {
123  lum = FilterLuminance::execute(imgIn, NULL, LT_CIE_LUMINANCE);
124  }
125 
126  Histogram m(lum, VS_LOG_2, 1024);
127  fstops = m.exposureCovering();
128 
129  if(imgIn->channels != 1) {
130  delete lum;
131  }
132 
133  return fstops;
134 }
135 
144 PIC_INLINE ImageVec getAllExposuresImages(Image *imgIn, std::vector<float> &fstops, float gamma = 2.2f)
145 {
146  ImageVec ret;
147  FilterSimpleTMO flt(gamma, 0.0f);
148 
149  ImageVec input = Single(imgIn);
150 
151  for(unsigned int i = 0; i < fstops.size(); i++) {
152  flt.update(gamma, fstops[i]);
153  Image *expo = flt.Process(input, NULL);
154 
155  expo->exposure = powf(2.0f, fstops[i]);
156  expo->clamp(0.0f, 1.0f);
157 
158  ret.push_back(expo);
159  }
160 
161  return ret;
162 }
163 
171 PIC_INLINE ImageVec getAllExposuresImages(Image *imgIn, float gamma = 2.2f)
172 {
173  std::vector<float> fstops = getAllExposures(imgIn);
174  return getAllExposuresImages(imgIn, fstops, gamma);
175 }
176 
177 } // end namespace pic
178 
179 #endif /* PIC_TONE_MAPPING_GET_ALL_EXPOSURES_HPP */
180 
Definition: filter_luminance.hpp:28
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
void clamp(float a, float b)
clamp set data values in the range [a,b]
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
PIC_INLINE long lround(double x)
lround rounds double numbers properly.
Definition: math.hpp:229
Definition: histogram.hpp:31
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
The FilterSimpleTMO class.
Definition: filter_simple_tmo.hpp:28
static T max(T *data, IntCoord &coord)
max computes the max value.
Definition: indexed_array.hpp:158
static void findSimple(T *data, int nData, bool(*func)(float), IntCoord &ret, int stride=1)
findSimple collects coordinates of data which satisfies a bool function func.
Definition: indexed_array.hpp:80
static T min(T *data, IntCoord &coord)
min computes the min value.
Definition: indexed_array.hpp:136
float exposure
Definition: image.hpp:79
std::vector< int > IntCoord
IntCoord.
Definition: indexed_array.hpp:30
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
void update(float gamma, float fstop)
update
Definition: filter_simple_tmo.hpp:62
PIC_INLINE void getMinMaxFstops(Image *imgIn, int &minFstop, int &maxFstop)
getMinMaxFstops computes the minimum and maximum f-stop values of an image.
Definition: get_all_exposures.hpp:39
PIC_INLINE std::vector< float > getAllExposures(Image *imgIn)
getAllExposures computes all required exposure values for reconstructing the input image using histog...
Definition: get_all_exposures.hpp:107
#define PIC_INLINE
Definition: base.hpp:33
std::vector< float > exposureCovering(int nBits=8, float overlap=1.0f)
exposureCovering computes the exposure values for fully covering the dynamic range of the image...
Definition: histogram.hpp:585
PIC_INLINE float log2f(float x)
log2f logarithm in base 2 for floating point
Definition: math.hpp:375
The Image class stores an image as buffer of float.
Definition: image.hpp:60
The IndexedArray class.
Definition: indexed_array.hpp:36
PIC_INLINE ImageVec getAllExposuresImages(Image *imgIn, std::vector< float > &fstops, float gamma=2.2f)
getAllExposuresImages converts an image into a stack of images.
Definition: get_all_exposures.hpp:144
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
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
PIC_INLINE std::vector< float > getAllExposuresUniform(Image *imgIn)
getAllExposuresUniform computes all required exposure values for reconstructing the input image using...
Definition: get_all_exposures.hpp:87