PICCANTE  0.4
The hottest HDR imaging library!
binarization.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_BINARIZATION_HPP
19 #define PIC_ALGORITHMS_BINARIZATION_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../image.hpp"
24 #include "../filtering/filter_luminance.hpp"
25 #include "../filtering/filter_gaussian_2d.hpp"
26 #include "../filtering/filter_threshold.hpp"
27 
28 namespace pic {
29 
36 PIC_INLINE Image *binarization(Image *imgIn, Image *imgOut = NULL, bool bAdaptive = false)
37 {
38  if(imgIn == NULL) {
39  return NULL;
40  }
41 
42  Image *imgIn_lum = FilterLuminance::execute(imgIn, NULL);
43 
44  if(bAdaptive) {
45  FilterThreshold flt_thr(0.0f, true);
46 
47  FilterGaussian2D flt_gauss(MIN(imgIn->widthf, imgIn->heightf) * 0.2f);
48  Image *imgIn_lum_flt = flt_gauss.Process(Single(imgIn_lum), NULL);
49 
50  imgOut = flt_thr.Process(Double(imgIn_lum, imgIn_lum_flt), imgOut);
51 
52  delete imgIn_lum_flt;
53  } else {
54  float mean_lum;
55 
56  imgIn_lum->getMeanVal(NULL, &mean_lum);
57 
58  FilterThreshold flt_thr(mean_lum, false);
59 
60  imgOut = flt_thr.Process(Single(imgIn_lum), imgOut);
61  }
62 
63  return imgOut;
64 }
65 
66 } // end namespace pic
67 
68 #endif /* PIC_ALGORITHMS_BINARIZATION_HPP */
69 
float * getMeanVal(BBox *box, float *ret)
getMeanVal computes the mean for the current Image.
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
PIC_INLINE Image * binarization(Image *imgIn, Image *imgOut=NULL, bool bAdaptive=false)
binarization
Definition: binarization.hpp:36
float heightf
Definition: image.hpp:84
The FilterThreshold class.
Definition: filter_threshold.hpp:31
PIC_INLINE ImageVec Double(Image *img1, Image *img2)
Double creates an std::vector which contains img1 and img2; this is for filters input.
Definition: image_vec.hpp:49
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_npasses.hpp:310
#define PIC_INLINE
Definition: base.hpp:33
float widthf
Definition: image.hpp:84
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
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
The FilterGaussian2D class.
Definition: filter_gaussian_2d.hpp:31