PICCANTE  0.4
The hottest HDR imaging library!
filter_threshold.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_THRESHOLD_HPP
19 #define PIC_FILTERING_FILTER_THRESHOLD_HPP
20 
21 #include "../image.hpp"
22 #include "../histogram.hpp"
23 #include "../filtering/filter.hpp"
24 #include "../filtering/filter_luminance.hpp"
25 
26 namespace pic {
27 
31 class FilterThreshold: public Filter
32 {
33 protected:
34  float threshold;
35  bool bAdaptive;
36 
43  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
44  {
45  Image* img = src[0];
46 
47  if(bAdaptive) {
48  if(src.size() < 2) {
49  return;
50  }
51 
52  Image* img_ada = src[1];
53 
54  for(int j = box->y0; j < box->y1; j++) {
55 
56  for(int i = box->x0; i < box->x1; i++) {
57  float *dst_val = (*dst)(i, j);
58  float *img_val = (*img)(i, j);
59  float *img_ada_val = (*img_ada)(i, j);
60 
61  dst_val[0] = img_val[0] > img_ada_val[0] ? 1.0f : 0.0f;
62  }
63  }
64  } else {
65  for(int j = box->y0; j < box->y1; j++) {
66 
67  for(int i = box->x0; i < box->x1; i++) {
68  float *dst_val = (*dst)(i, j);
69  float *img_val = (*img)(i, j);
70 
71  dst_val[0] = img_val[0] > threshold ? 1.0f : 0.0f;
72  }
73  }
74  }
75  }
76 
77 public:
78 
84  FilterThreshold(float threshold = 0.5f, bool bAdaptive = false) : Filter()
85  {
87  }
88 
94  void update(float threshold, bool bAdaptive)
95  {
96  this->threshold = threshold;
97  this->bAdaptive = bAdaptive;
98  }
99 
108  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
109  {
110  width = imgIn[0]->width;
111  height = imgIn[0]->height;
112  channels = 1;
113  frames = imgIn[0]->frames;
114  }
115 
116  static Image* execute(Image* imgIn, Image *imgOut, float threshold, bool bAdaptive)
117  {
119  imgOut = flt.Process(Single(imgIn), imgOut);
120  return imgOut;
121  }
122 
123  static Image* Otsu(Image* imgIn, Image *imgOut)
124  {
125  if(imgIn == NULL) {
126  return imgOut;
127  }
128 
129  pic::Image *imgLum;
130  if(imgIn->channels == 3) {
131  imgLum = pic::FilterLuminance::execute(imgIn, NULL);
132  } else {
133  imgLum = imgIn;
134  }
135 
136  pic::Histogram h;
137  h.calculate(imgLum, pic::VS_LIN, 1024, NULL, 0);
138  float thr = h.getOtsu();
139  imgOut = pic::FilterThreshold::execute(imgLum, imgOut, thr, false);
140 
141  if(imgIn->channels == 3) {
142  delete imgLum;
143  }
144 
145  return imgOut;
146  }
147 };
148 
149 } // end namespace pic
150 
151 #endif /* PIC_FILTERING_FILTER_THRESHOLD_HPP */
152 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
int channels
Definition: image.hpp:80
static Image * execute(Image *imgIn, Image *imgOut, float threshold, bool bAdaptive)
Definition: filter_threshold.hpp:116
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: display.hpp:166
The Filter class.
Definition: filter.hpp:50
The Image class stores an image as buffer of float.
Definition: filter_radial_basis_function.hpp:60
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
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: display.hpp:213
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_threshold.hpp:108
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_threshold.hpp:43
int y0
Definition: bbox.hpp:32
The Histogram class is a class for creating, managing, loading, and saving histogram for an Image...
Definition: display.hpp:37
The FilterThreshold class.
Definition: filter_threshold.hpp:31
static Image * Otsu(Image *imgIn, Image *imgOut)
Definition: filter_threshold.hpp:123
void update(float threshold, bool bAdaptive)
update
Definition: filter_threshold.hpp:94
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
float threshold
Definition: filter_threshold.hpp:34
FilterThreshold(float threshold=0.5f, bool bAdaptive=false)
FilterThreshold.
Definition: filter_threshold.hpp:84
float getOtsu()
getOtsu
Definition: display.hpp:516
bool bAdaptive
Definition: filter_threshold.hpp:35
Definition: display.hpp:31