PICCANTE  0.4
The hottest HDR imaging library!
color_classification.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_ALGORITHMS_COLOR_CLASSIFICATION_HPP
19 #define PIC_ALGORITHMS_COLOR_CLASSIFICATION_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../util/math.hpp"
24 
25 #include "../image.hpp"
26 #include "../filtering/filter_radial_basis_function.hpp"
27 #include "../filtering/filter_white_balance.hpp"
28 #include "../filtering/filter_luminance.hpp"
29 #include "../algorithms/lischinski_minimization.hpp"
30 #include "../util/mask.hpp"
31 
32 namespace pic {
33 
34 #ifndef PIC_DISABLE_EIGEN
35 
46 PIC_INLINE bool *computeColorClassification(Image *img, float *white_pixel, float *color_samples, int nSamples, int nDim, float variance)
47 {
48  if(color_samples == NULL || nSamples < 1 || nDim < 1 || variance <= 0.0f) {
49  return NULL;
50  }
51 
53  rbf.update(color_samples, nSamples, nDim, variance);
54 
56  flt_rbf.update(&rbf);
57 
58  FilterWhiteBalance flt_wb;
59  flt_wb.update(white_pixel, img->channels, true);
60 
61  Image *img_wb = NULL;
62 
63  bool bFlag = true;
64  if(white_pixel != NULL) {
65  img_wb = FilterWhiteBalance::execute(img, white_pixel, NULL);
66  } else {
67  img_wb = img;
68  bFlag = false;
69  }
70 
71  #ifdef PIC_DEBUG
72  img_wb->Write("../data/output/s_input_wb.bmp");
73  #endif
74 
75  Image *img_wb_rbf = flt_rbf.Process(Single(img_wb), NULL);
76 
77  img_wb_rbf->clamp(0.0f, 1.0f);
78 
79  Image *img_L = FilterLuminance::execute(img, NULL);
80 
81  Image *opt = LischinskiMinimization(img_L, img_wb_rbf);
82 
83  float value = 1.0f;
84  bool *mask = opt->convertToMask(&value, 0.25f, false, NULL);
85 
86  int width = opt->width;
87  int height = opt->height;
88  bool *tmp;
89  tmp = Mask::dilate(NULL, mask, width, height, 3);
90  Mask::dilate(mask, tmp, width, height, 3);
91  Mask::dilate(tmp, mask, width, height, 3);
92  Mask::dilate(mask, tmp, width, height, 3);
93 
94  Mask::removeIsolatedPixels(tmp, mask, width, height);
95 
96  Mask::erode(mask, tmp, width, height, 3);
97  Mask::erode(tmp, mask, width, height, 3);
98  Mask::erode(mask, tmp, width, height, 3);
99 
100  #ifdef PIC_DEBUG
101  opt->convertFromMask(mask, width, height);
102  opt->Write("../data/output/opt.bmp");
103  #endif
104 
105  if(tmp != mask) {
106  delete[] tmp;
107  }
108 
109  delete opt;
110  delete img_L;
111  delete img_wb_rbf;
112 
113  if(bFlag) {
114  delete img_wb;
115  }
116 
117  return mask;
118 }
119 #endif
120 
121 } // end namespace pic
122 
123 #endif /* PIC_ALGORITHMS_COLOR_CLASSIFICATION_HPP */
void update(RadialBasisFunction *rbf)
update
Definition: filter_radial_basis_function.hpp:96
int channels
Definition: image.hpp:80
void clamp(float a, float b)
clamp set data values in the range [a,b]
void update(float *centers, int nCenters, int nDim, float var)
update
Definition: radial_basis_function.hpp:59
PIC_INLINE bool * computeColorClassification(Image *img, float *white_pixel, float *color_samples, int nSamples, int nDim, float variance)
computeColorClassification
Definition: color_classification.hpp:46
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
PIC_INLINE Image * LischinskiMinimization(Image *L, Image *g, Image *omega=NULL, float omega_global=1.0f, Image *gOut=NULL, float alpha=1.0f, float lambda=0.4f, float LISCHINSKI_EPSILON=1e-4f)
LischinskiMinimization.
Definition: lischinski_minimization.hpp:82
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
bool * convertToMask(float *color, float threshold, bool cmp, bool *mask)
convertToMask converts an Image into a boolean mask.
The FilterWhiteBalance class.
Definition: filter_white_balance.hpp:31
static bool * erode(bool *dataOut, bool *dataIn, int width, int height, int kernelSize=3)
erode erodes a mask.
Definition: mask.hpp:89
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static Image * execute(Image *imgIn, float *white_color, Image *out)
execute
Definition: filter_white_balance.hpp:162
void update(float *white, unsigned int nWhite, bool bComputeScalingFactors)
update
Definition: filter_white_balance.hpp:135
static bool * dilate(bool *dataOut, bool *dataIn, int width, int height, int kernelSize=3)
MaskDilate dilates a mask.
Definition: mask.hpp:137
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 bool * removeIsolatedPixels(bool *dataOut, bool *dataIn, int width, int height)
removeIsolatedPixels removes isolated pixels.
Definition: mask.hpp:38
void convertFromMask(bool *mask, int width, int height)
convertFromMask converts a boolean mask into an Image. true is mapped to 1.0f, and false is mapped to...
The RadialBasisFunction class.
Definition: radial_basis_function.hpp:30
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
The FilterRadialBasisFunction class.
Definition: filter_radial_basis_function.hpp:30