PICCANTE  0.4
The hottest HDR imaging library!
filter_disparity.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_DISPARITY_HPP
19 #define PIC_FILTERING_FILTER_DISPARITY_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 #include "../features_matching/patch_comp.hpp"
24 
25 namespace pic {
26 
30 class FilterDisparity: public Filter
31 {
32 protected:
33 
35  float lambda;
37 
44  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
45  {
46  float maxDisparityf = float(maxDisparity);
47  float patchSize_sq = float (patchSize * patchSize);
48 
49  for(int j = box->y0; j < box->y1; j++) {
50 
51  for(int i = box->x0; i < box->x1; i++) {
52 
53  float *prevL = (*dst)(i - 1, j );
54  float *prevU = (*dst)(i , j - 1);
55 
56  int xB = -1;
57  float dB = FLT_MAX;
58 
59  int minX = MAX(i - halfMaxDisparity, 0);
60  int maxX = MIN(i + halfMaxDisparity, src[1]->width);
61 
62  for(int x = minX; x < maxX; x++) {
63 
64  float dist = pc->getSSDSmooth(i, j, x, j) / patchSize_sq;
65 
66  //regularization
67  float reg = 0.0f;//float(x1 - x0);
68 
69  if(prevL[1] >= 0.0f) {
70  float deltaL = fabsf(prevL[0] - x);
71  reg += deltaL / maxDisparityf;
72  }
73 
74  if(prevU[1] >= 0.0f) {
75  float deltaU = fabsf(prevU[0] - x);
76  reg += deltaU / maxDisparityf;
77  }
78 
79  dist += lambda * reg;
80 
81  if(dist < dB) {
82  xB = x;
83  dB = dist;
84  }
85  }
86 
87  float *out = (*dst)(i, j);
88 
89  out[1] = dB;
90  out[0] = float(xB);
91  }
92  }
93  }
94 
101  Image *setupAux(ImageVec imgIn, Image *imgOut)
102  {
103  if(imgIn.size() == 4) {
104  pc = new PatchComp(imgIn[0], imgIn[1], imgIn[2], imgIn[3], patchSize, 0.9f);
105  } else {
106  return NULL;
107  }
108 
109  if(imgOut == NULL) {
110  imgOut = new Image(1, imgIn[0]->width, imgIn[0]->height, 2);
111  } else {
112  if(imgOut->isValid()) {
113 
114  if((imgIn[0]->width != imgOut->width) ||
115  (imgIn[0]->height != imgOut->height) ||
116  (imgOut->channels != 2)) {
117  imgOut = new Image(1, imgIn[0]->width, imgIn[0]->height, 2);
118  }
119  } else {
120  imgOut->allocateSimilarTo(imgIn[0]);
121  }
122  }
123 
124  *imgOut = -1.0f;
125 
126  return imgOut;
127  }
128 
129 public:
130 
135  {
136  update(200, 7, 0.05f);
137  }
138 
146  {
147  pc = NULL;
149  }
150 
152  {
153  delete_s(pc);
154  }
155 
160  void update(int maxDisparity, int patchSize, float lambda)
161  {
162  if(this->patchSize != patchSize) {
163  delete_s(pc);
164  }
165 
166  this->lambda = lambda > 0.0f ? lambda : 0.05f;
167 
168  this->maxDisparity = maxDisparity;
169  this->halfMaxDisparity = maxDisparity >> 1;
170  this->patchSize = patchSize;
171  }
172 
181  void OutputSize(Image *imgIn, int &width, int &height, int &channels, int &frames)
182  {
183  width = imgIn->width;
184  height = imgIn->height;
185  channels = 2;
186  frames = imgIn->frames;
187  }
188 };
189 
190 } // end namespace pic
191 
192 #endif /* PIC_FILTERING_FILTER_DISPARITY_HPP */
193 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
void OutputSize(Image *imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_disparity.hpp:181
int maxDisparity
Definition: filter_disparity.hpp:34
int channels
Definition: image.hpp:80
void update(int maxDisparity, int patchSize, float lambda)
update
Definition: filter_disparity.hpp:160
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
~FilterDisparity()
Definition: filter_disparity.hpp:151
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
float getSSDSmooth(int x0, int y0, int x1, int y1)
getSSDSmooth
Definition: patch_comp.hpp:140
int halfMaxDisparity
Definition: filter_disparity.hpp:34
The Filter class.
Definition: filter.hpp:50
void allocateSimilarTo(Image *img)
allocateSimilarTo allocate an Image with similar size of the passed by.
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_disparity.hpp:44
int frames
Definition: image.hpp:80
The PatchComp class.
Definition: patch_comp.hpp:36
int y0
Definition: bbox.hpp:32
Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter_disparity.hpp:101
PatchComp * pc
Definition: filter_disparity.hpp:36
#define MIN(a, b)
Definition: math.hpp:69
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
float lambda
Definition: filter_disparity.hpp:35
FilterDisparity()
FilterDisparity.
Definition: filter_disparity.hpp:134
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...
#define MAX(a, b)
Definition: math.hpp:73
The FilterDisparity class.
Definition: filter_disparity.hpp:30
FilterDisparity(int maxDisparity, int patchSize, float lambda)
FilterDisparity.
Definition: filter_disparity.hpp:145
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
int patchSize
Definition: filter_disparity.hpp:34