PICCANTE  0.4
The hottest HDR imaging library!
patch_comp.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_FEATURES_MATCHING_PATCH_COMP_HPP
19 #define PIC_FEATURES_MATCHING_PATCH_COMP_HPP
20 
21 #include "../image.hpp"
22 
23 #include "../util/math.hpp"
24 #include "../util/std_util.hpp"
25 #include "../util/array.hpp"
26 
27 #include "../image_samplers/image_sampler_bilinear.hpp"
28 
29 #include "../features_matching/transform_data.hpp"
30 
31 namespace pic {
32 
36 class PatchComp
37 {
38 protected:
40 
42 
43  //patchsize
45  float patchSize_sq;
46 
47  //stereo
48  float alpha;
49 
50 public:
51 
56  {
57  setNULL();
58  }
59 
67  {
68  setNULL();
69 
70  setup(img0, img1, NULL, NULL, patchSize, 0.05f);
71  }
72 
82  int patchSize, float alpha)
83  {
84  setNULL();
86  }
87 
91  void setNULL()
92  {
93  img0 = NULL;
94  img0_g = NULL;
95  img1 = NULL;
96  img1_g = NULL;
97 
98  alpha = -1.0f;
99 
100  patchSize = -1;
101  halfPatchSize = -1;
102  }
103 
112  int patchSize, float alpha)
113  {
114  if(patchSize < 1) {
115  return;
116  }
117 
118  this->img0 = img0;
119  this->img1 = img1;
120  this->img0_g = img0_g;
121  this->img1_g = img1_g;
122 
123  this->alpha = CLAMPi(alpha, 0.0f, 1.0f);
124 
125  if(this->patchSize != patchSize) {
126  this->patchSize_sq = float(patchSize * patchSize);
127  this->halfPatchSize = patchSize >> 1;
128  this->patchSize = (halfPatchSize << 1) + 1;
129  }
130  }
131 
140  float getSSDSmooth(int x0, int y0, int x1, int y1)
141  {
142  float alpha_i = 1.0f - alpha;
143 
144  float ret = 0.0f;
145 
146  for(int i = -halfPatchSize; i <= halfPatchSize; i++) {
147  for(int j = -halfPatchSize; j <= halfPatchSize; j++) {
148  float *img0_ij = (*img0)(x0 + j, y0 + i);
149  float *img1_ij = (*img1)(x1 + j, y1 + i);
150 
151  float *img0_g_ij = (*img0_g)(x0 + j, y0 + i);
152  float *img1_g_ij = (*img1_g)(x1 + j, y1 + i);
153 
154  //color term
155  float err_col = sqrtf(Arrayf::distanceSq(img1_ij, img0_ij, img0->channels));
156 
157  //gradient term
158  float err_grad = sqrtf(Arrayf::distanceSq(img0_g_ij, img1_g_ij, 2));
159 
160  //err term
161  ret += alpha_i * err_col + alpha * err_grad;
162 
163  }
164  }
165 
166  return ret;
167  }
168 
177  float getSSD(int x0, int y0, int x1, int y1)
178  {
179  float ret = 0.0f;
180  for(int i = -halfPatchSize; i <= halfPatchSize; i++) {
181  for(int j = -halfPatchSize; j <= halfPatchSize; j++) {
182  float *img0_ij = (*img0)(x0 + j, y0 + i);
183  float *img1_ij = (*img1)(x1 + j, y1 + i);
184 
185  ret += Arrayf::distanceSq(img0_ij, img1_ij, img0->channels);
186  }
187  }
188 
189  return ret;
190  }
191 };
192 
193 } // end namespace pic
194 
195 #endif /* PIC_FEATURES_MATCHING_PATCH_COMP_HPP */
196 
Image * img0_g
Definition: patch_comp.hpp:41
PatchComp(Image *img0, Image *img1, Image *img0_g, Image *img1_g, int patchSize, float alpha)
PatchComp.
Definition: patch_comp.hpp:80
ImageSamplerBilinear isb
Definition: patch_comp.hpp:39
int halfPatchSize
Definition: patch_comp.hpp:44
int channels
Definition: image.hpp:80
float getSSDSmooth(int x0, int y0, int x1, int y1)
getSSDSmooth
Definition: patch_comp.hpp:140
void setup(Image *img0, Image *img1, Image *img0_g, Image *img1_g, int patchSize, float alpha)
setup
Definition: patch_comp.hpp:110
float patchSize_sq
Definition: patch_comp.hpp:45
Image * img0
Definition: patch_comp.hpp:41
The PatchComp class.
Definition: patch_comp.hpp:36
void setNULL()
setNULL
Definition: patch_comp.hpp:91
static T distanceSq(T *data0, T *data1, int n)
distanceSq
Definition: array.hpp:195
float getSSD(int x0, int y0, int x1, int y1)
getSSD
Definition: patch_comp.hpp:177
PatchComp(Image *img0, Image *img1, int patchSize)
PatchComp.
Definition: patch_comp.hpp:66
float alpha
Definition: patch_comp.hpp:48
int patchSize
Definition: patch_comp.hpp:44
Image * img1
Definition: patch_comp.hpp:41
The Image class stores an image as buffer of float.
Definition: image.hpp:60
#define CLAMPi(x, a, b)
Definition: math.hpp:81
Definition: bilateral_separation.hpp:25
Image * img1_g
Definition: patch_comp.hpp:41
The ImageSamplerBilinear class.
Definition: image_sampler_bilinear.hpp:28
PatchComp()
PatchComp.
Definition: patch_comp.hpp:55