PICCANTE  0.4
The hottest HDR imaging library!
filter_remove_inf_nan.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_REMOVE_INF_NAN_HPP
19 #define PIC_FILTERING_FILTER_REMOVE_INF_NAN_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31 
38  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
39  {
40  float values[9];
41 
42  int channels = dst->channels;
43 
44  for(int j = box->y0; j < box->y1; j++) {
45  for(int i = box->x0; i < box->x1; i++) {
46 
47  float *tmp_data = (*src[0])(i, j);
48  float *tmp_dst = (*dst )(i, j);
49 
50  for(int ch = 0; ch < channels; ch++) {
51 
52  float val = tmp_data[ch];
53 
54  if(isinf(val) || isnan(val)) {
55  int c2 = 0;
56 
57  for(int k = -1; k <= 1; k++) {
58  for(int l = -1; l <= 1; l++) {
59 
60  float *tmp_val = (*src[0])(i + l, j + k);
61 
62  if(!(isnan(tmp_val[ch]) || isinf(tmp_val[ch]))) {
63  values[c2] = tmp_val[ch];
64  c2++;
65  }
66  }
67  }
68 
69  if(c2 == 0) {
70  tmp_dst[ch] = 0.0f;
71  } else {
72  std::sort(values, values + c2);
73  tmp_dst[ch] = values[5];
74  }
75  } else {
76  tmp_dst[ch] = val;
77  }
78  }
79  }
80  }
81  }
82 
83 
84 public:
89  {
90  }
91 
99  static Image* execute(Image *imgIn, Image *imgOut)
100  {
101  FilterRemoveInfNaN filter;
102  imgOut = filter.Process(Single(imgIn), imgOut);
103  return imgOut;
104  }
105 };
106 
107 } // end namespace pic
108 
109 #endif /* PIC_FILTERING_FILTER_REMOVE_INF_NAN_HPP */
110 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
The FilterRemoveInfNaN class.
Definition: filter_remove_inf_nan.hpp:28
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
PIC_INLINE bool isinf(T value)
isinf is it a Inf value?
Definition: math.hpp:103
int y0
Definition: bbox.hpp:32
PIC_INLINE bool isnan(T value)
isnan is it a NaN?
Definition: math.hpp:93
FilterRemoveInfNaN()
FilterRemoveInfNaN.
Definition: filter_remove_inf_nan.hpp:88
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_remove_inf_nan.hpp:38
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 Image * execute(Image *imgIn, Image *imgOut)
execute
Definition: filter_remove_inf_nan.hpp:99